提交 34658fa5 编写于 作者: sq3536's avatar sq3536

Merge remote-tracking branch 'origin/master'

...@@ -10,22 +10,20 @@ ...@@ -10,22 +10,20 @@
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script> <script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script> <script>
/**
* 初始化
*/
$(function () { $(function () {
var code = getUrlParam('code'); var code = getUrlParam('code');
var state = getUrlParam('state'); var state = getUrlParam('state');
// alert("code:" + code + "\n state:" + state);
if (code && state) { if (code && state) {
// 通过授权code请求后台 // 通过授权code请求后台
var opt = {"code": code, "state": state};
$.ajax({ $.ajax({
type: "post", type: "get",
url: "../uaa/queryDingtalkUserByCode", url: "../uaa/open/dingtalk/sns/" + code + "?state=" + state,
dataType: "json", dataType: "json",
data: JSON.stringify(opt),
contentType: 'application/json', contentType: 'application/json',
success: function (data) { success: function (data) {
// console.log(JSON.stringify(data));
if (data) { if (data) {
if (data.openid) { if (data.openid) {
localStorage.setItem('openid', data.openid); localStorage.setItem('openid', data.openid);
...@@ -33,17 +31,17 @@ ...@@ -33,17 +31,17 @@
if (data.nickname) { if (data.nickname) {
localStorage.setItem('nickname', data.nickname); localStorage.setItem('nickname', data.nickname);
} }
if (data.unionid) {
localStorage.setItem('unionid',data.unionid);
}
if (data.token) { if (data.token) {
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); var user = data.user;
} localStorage.setItem('user',JSON.stringify(user));
if (data.ibzuser) { // 设置cookie,保存账号7天
var ibzuser = data.ibzuser; setCookie("loginname", ibzuser.loginname, 7);
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天
setCookie(ibzuser.loginname, ibzuser.password, 7);
// 跳转首页 // 跳转首页
window.location.href = "../index"; window.location.href = "../index";
} else { } else {
...@@ -65,7 +63,11 @@ ...@@ -65,7 +63,11 @@
}); });
// 获取url中的参数 /**
* 获取url中的参数
* @param name
* @returns {*}
*/
function getUrlParam(name) { function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //匹配目标参数
...@@ -73,7 +75,12 @@ ...@@ -73,7 +75,12 @@
return null; //返回参数值 return null; //返回参数值
} }
// 设置Cookie /**
* 设置Cookie
* @param name
* @param value
* @param day
*/
function setCookie(name, value, day) { function setCookie(name, value, day) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
var curDate = new Date(); var curDate = new Date();
...@@ -83,7 +90,7 @@ ...@@ -83,7 +90,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
......
...@@ -10,44 +10,42 @@ ...@@ -10,44 +10,42 @@
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script> <script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script> <script>
/**
* 初始化
*/
$(function () { $(function () {
var code = getUrlParam('code'); var code = getUrlParam('code');
var state = getUrlParam('state'); var state = getUrlParam('state');
// alert("code:" + code + "\n state:" + state);
if (code && state) { if (code && state) {
// 通过授权code请求后台 // 通过授权code请求后台
var opt = {"code": code, "state": state};
$.ajax({ $.ajax({
type: "post", type: "get",
url: "../uaa/queryQQUserByCode", url: "../uaa/open/qq/sns/" + code + "?state" + state,
dataType: "json", dataType: "json",
data: JSON.stringify(opt),
contentType: 'application/json', contentType: 'application/json',
success: function (data) { success: function (data) {
// console.log(JSON.stringify(data));
if (data) { if (data) {
if (data.openid) { if (data.openid) {
localStorage.setItem('openid', data.openid); localStorage.setItem('openid', data.openid);
} }
if (data.nickname) { if (data.access_token) {
localStorage.setItem('nickname', data.nickname); localStorage.setItem('access_token',data.access_token);
}
if (data.refresh_token) {
localStorage.setItem('refresh_token',data.refresh_token);
} }
if (data.token) { if (data.token) {
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); var user = data.user;
} localStorage.setItem('user', JSON.stringify(user));
if (data.ibzuser) { // 设置cookie,保存账号7天
var ibzuser = data.ibzuser; setCookie("loginname", user.loginname, 7);
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天
setCookie(ibzuser.loginname, ibzuser.password, 7);
// 跳转首页 // 跳转首页
window.location.href = "../index"; window.location.href = "../index";
} else { } else {
// 跳转微信绑定 // 跳转qq绑定
window.location.href = "../#/qqLoginRedirect?code=" + code + "&state=" + state; window.location.href = "../#/qqLoginRedirect?code=" + code + "&state=" + state;
} }
} }
...@@ -65,7 +63,11 @@ ...@@ -65,7 +63,11 @@
}); });
// 获取url中的参数 /**
* 获取url中的参数
* @param name
* @returns {*}
*/
function getUrlParam(name) { function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //匹配目标参数
...@@ -73,7 +75,12 @@ ...@@ -73,7 +75,12 @@
return null; //返回参数值 return null; //返回参数值
} }
// 设置Cookie /**
* 设置Cookie
* @param name
* @param value
* @param day
*/
function setCookie(name, value, day) { function setCookie(name, value, day) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
var curDate = new Date(); var curDate = new Date();
...@@ -83,7 +90,7 @@ ...@@ -83,7 +90,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
......
...@@ -10,39 +10,41 @@ ...@@ -10,39 +10,41 @@
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script> <script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script> <script>
/**
* 初始化
*/
$(function () { $(function () {
var code = getUrlParam('code'); var code = getUrlParam('code');
var state = getUrlParam('state'); var state = getUrlParam('state');
// alert("code:" + code + "\n state:" + state);
if (code && state) { if (code && state) {
// 通过授权code请求后台 // 通过授权code请求后台
var opt = {"code": code, "state": state};
$.ajax({ $.ajax({
type: "post", type: "get",
url: "../uaa/queryWechatUserByCode", url: "../uaa/open/wechat/sns/" + code + "?state=" + state,
dataType: "json", dataType: "json",
data: JSON.stringify(opt),
contentType: 'application/json', contentType: 'application/json',
success: function (data) { success: function (data) {
if (data) { if (data) {
if (data.openid) { if (data.openid) {
localStorage.setItem('openid', data.openid); localStorage.setItem('openid', data.openid);
} }
if (data.nickname) { if (data.access_token) {
localStorage.setItem('nickname', data.nickname); localStorage.setItem('access_token',data.access_token);
}
if (data.refresh_token) {
localStorage.setItem('refresh_token',data.refresh_token);
}
if (data.unionid) {
localStorage.setItem('unionid',data.unionid);
} }
if (data.token) { if (data.token) {
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); var user = data.user;
} localStorage.setItem('user', JSON.stringify(user));
if (data.ibzuser) { // 设置cookie,保存账号7天
var ibzuser = data.ibzuser; setCookie("loginname", user.loginname, 7);
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天
setCookie(ibzuser.loginname, ibzuser.password, 7);
// 跳转首页 // 跳转首页
window.location.href = "../index"; window.location.href = "../index";
} else { } else {
...@@ -64,7 +66,11 @@ ...@@ -64,7 +66,11 @@
}); });
// 获取url中的参数 /**
* 回去url中的参数
* @param name
* @returns {*}
*/
function getUrlParam(name) { function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
var r = window.location.search.substr(1).match(reg); //匹配目标参数 var r = window.location.search.substr(1).match(reg); //匹配目标参数
...@@ -72,7 +78,12 @@ ...@@ -72,7 +78,12 @@
return null; //返回参数值 return null; //返回参数值
} }
// 设置Cookie /**
* 设置Cookie
* @param name
* @param value
* @param day
*/
function setCookie(name, value, day) { function setCookie(name, value, day) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
var curDate = new Date(); var curDate = new Date();
...@@ -82,11 +93,12 @@ ...@@ -82,11 +93,12 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
} }
</script> </script>
</head> </head>
......
...@@ -62,37 +62,25 @@ ...@@ -62,37 +62,25 @@
}) })
export default class dingdingLoginRedirect extends Vue { export default class dingdingLoginRedirect extends Vue {
/** // 表单
* 表单对象
*
* @type {*}
* @memberof Register
*/
public form: any = {loginname: '', password: ''}; public form: any = {loginname: '', password: ''};
/** // 按钮可点击
* 按钮可点击
*/
public canClick: any = true; public canClick: any = true;
/** // 按钮内容
* 按钮内容
*/
public BtnContent: any = "注册并绑定钉钉"; public BtnContent: any = "注册并绑定钉钉";
/** // 钉钉授权成功返回的code和state
* 钉钉授权成功返回的code和state
*/
public code: any; public code: any;
public state: any; public state: any;
/**
* 钉钉用户身份的唯一标识 public dingtalkUserInfo:any ={
*/ openid:'',// 钉钉用户身份的唯一标识
public openid: any; nickname:'',// 钉钉用户名称
/** unionid:'',// 钉钉用户唯一标识
* 钉钉用户名称 }
*/
public nickname: any;
/** /**
* 应用名称 * 应用名称
...@@ -139,7 +127,6 @@ ...@@ -139,7 +127,6 @@
* 挂载 * 挂载
*/ */
public mounted() { public mounted() {
// 从url获取授权code和state // 从url获取授权code和state
this.code = this.$route.query.code; this.code = this.$route.query.code;
if (!this.code) { if (!this.code) {
...@@ -155,12 +142,15 @@ ...@@ -155,12 +142,15 @@
this.goLogin(); this.goLogin();
} }
else { else {
// 从local中获取该用户的openid和nickname // 从local中获取钉钉用户的openid,可用于后续请求及绑定操作
if (localStorage.getItem("openid")) { if (localStorage.getItem("openid")) {
this.openid = localStorage.getItem("openid"); this.dingtalkUserInfo.openid = localStorage.getItem("openid");
} }
if (localStorage.getItem("nickname")) { if (localStorage.getItem("nickname")) {
this.nickname = localStorage.getItem("nickname"); this.dingtalkUserInfo.nickname = localStorage.getItem("nickname");
}
if (localStorage.getItem("unionid")) {
this.dingtalkUserInfo.unionid = localStorage.getItem("unionid");
} }
} }
...@@ -190,6 +180,7 @@ ...@@ -190,6 +180,7 @@
/** /**
* 获取url参数 * 获取url参数
* @param name
*/ */
public getUrlParam(name: any) { public getUrlParam(name: any) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
...@@ -216,18 +207,17 @@ ...@@ -216,18 +207,17 @@
if (!validatestate) { if (!validatestate) {
return; return;
} }
// 请求传参 // 请求传参
var param: any = this.form; var param: any = this.form;
if (this.code && this.state) { if (this.code && this.state) {
param.openid = this.openid; param.openid = this.dingtalkUserInfo.openid;
param.nickname = this.nickname; param.nickname = this.dingtalkUserInfo.nickname;
} else { } else {
this.$message.error("钉钉授权,获取code失败"); this.$message.error("钉钉授权,获取code失败");
return; return;
} }
// post请求绑定钉钉
const post: Promise<any> = this.$http.post('/uaa/bindDingtalkToRegister', param, true); const post: Promise<any> = this.$http.post('/uaa/open/dingtalk/bind', param, true);
post.then((response: any) => { post.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
...@@ -239,13 +229,10 @@ ...@@ -239,13 +229,10 @@
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); let user: any = data.user;
} localStorage.setItem('user',JSON.stringify(user));
if (data.ibzuser) { // 设置cookie,保存账号7天
let ibzuser: any = data.ibzuser; this.setCookie("loginname", user.loginname, 7);
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天
this.setCookie(ibzuser.loginname, ibzuser.password, 7);
// 跳转首页 // 跳转首页
const url: any = '*'; const url: any = '*';
this.$router.push({path: url}); this.$router.push({path: url});
...@@ -273,9 +260,11 @@ ...@@ -273,9 +260,11 @@
} }
/** /**
* 设置cookie * 设置Cookie
* @param name
* @param value
* @param day
*/ */
public setCookie(name: any, value: any, day: any) { public setCookie(name: any, value: any, day: any) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
...@@ -286,7 +275,7 @@ ...@@ -286,7 +275,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
......
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
* @type {*} * @type {*}
* @memberof Login * @memberof Login
*/ */
public form: any = {loginname: 'guest', password: '123456'}; public form: any = {loginname: 'ibzadmin', password: '123456'};
/** /**
...@@ -134,17 +134,14 @@ ...@@ -134,17 +134,14 @@
} }
public mounted() { public mounted() {
if (this.getCookie("loginname") && this.getCookie("loginname") !== 'undefined' if (this.getCookie("loginname") && this.getCookie("loginname") !== 'undefined') {
&& this.getCookie("password") && this.getCookie("password") !== 'undefined') {
this.form.loginname = this.getCookie("loginname"); this.form.loginname = this.getCookie("loginname");
this.form.password = this.getCookie("password");
}else { }else {
if (localStorage.getItem("ibzuser")) { if (localStorage.getItem("user")) {
const ibzuser:any = localStorage.getItem("ibzuser"); const user:any = localStorage.getItem("user");
if (ibzuser) { if (user) {
const ibzuserObj:any = JSON.parse(ibzuser); const userObj:any = JSON.parse(user);
this.form.loginname = ibzuserObj.loginname; this.form.loginname = userObj.loginname;
this.form.password = ibzuserObj.password;
} }
} }
} }
...@@ -245,7 +242,7 @@ ...@@ -245,7 +242,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
...@@ -272,7 +269,7 @@ ...@@ -272,7 +269,7 @@
const baseUrl = this.getNeedLocation(); const baseUrl = this.getNeedLocation();
// 从后台获取qq互联创建的网站应用appid // 从后台获取qq互联创建的网站应用appid
const get: Promise<any> = this.$http.get('/uaa/getQQAppId'); const get: Promise<any> = this.$http.get('/uaa/open/qq/appid');
get.then((response: any) => { get.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
...@@ -326,7 +323,7 @@ ...@@ -326,7 +323,7 @@
*/ */
public wechatHandleClick(thirdpart: any) { public wechatHandleClick(thirdpart: any) {
// 从后台获取微信开放平台提供的appid // 从后台获取微信开放平台提供的appid
const get: Promise<any> = this.$http.get('/uaa/getWechatAppId'); const get: Promise<any> = this.$http.get('/uaa/open/wechat/appid');
get.then((response: any) => { get.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
...@@ -381,7 +378,7 @@ ...@@ -381,7 +378,7 @@
*/ */
public dingtalkHandleClick(thirdpart: any) { public dingtalkHandleClick(thirdpart: any) {
// 从后台获取钉钉开放平台提供的appid // 从后台获取钉钉开放平台提供的appid
const get: Promise<any> = this.$http.get('/uaa/getDingtalkAppId'); const get: Promise<any> = this.$http.get('/uaa/open/dingtalk/appid');
get.then((response: any) => { get.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
......
...@@ -62,41 +62,22 @@ ...@@ -62,41 +62,22 @@
}) })
export default class qqLoginRedirect extends Vue { export default class qqLoginRedirect extends Vue {
/** // 表单
* 表单对象
*
* @type {*}
* @memberof Register
*/
public form: any = {loginname: '', password: ''}; public form: any = {loginname: '', password: ''};
// 按钮可点击
/**
* 按钮可点击
*/
public canClick: any = true; public canClick: any = true;
// 按钮内容
/**
* 按钮内容
*/
public BtnContent: any = "注册并绑定QQ"; public BtnContent: any = "注册并绑定QQ";
// qq授权成功后返回的code和state
/**
* QQ授权成功返回的code和state
*/
public code: any; public code: any;
public state: any; public state: any;
// qq用户信息
/** public qqUserInfo: any = {
* QQ用户身份的唯一标识 openid:'',//QQ用户身份的唯一标识
*/ nickname:'',// QQ用户名称
public openid: any; access_token: '',// 临时授权token
refresh_token:'',// 刷新授权token
/** }
* QQ用户名称
*/
public nickname: any;
/** /**
* 应用名称 * 应用名称
...@@ -144,7 +125,6 @@ ...@@ -144,7 +125,6 @@
* 挂载 * 挂载
*/ */
public mounted() { public mounted() {
// 从url获取授权code和state // 从url获取授权code和state
this.code = this.$route.query.code; this.code = this.$route.query.code;
if (!this.code) { if (!this.code) {
...@@ -154,18 +134,20 @@ ...@@ -154,18 +134,20 @@
if (!this.state) { if (!this.state) {
this.state = this.getUrlParam('state'); this.state = this.getUrlParam('state');
} }
// 获取失败,回到登录页 // 获取授权code和state失败,回到登录页重新授权
if (!this.code || !this.state) { if (!this.code || !this.state) {
this.$message.error("QQ授权,获取code失败"); this.$message.error("QQ授权,获取code失败");
this.goLogin(); this.goLogin();
} } else {
else { // 从local中获取qq用户的授权openid,可用于后续请求及绑定操作
// 从local中获取该用户的openid和nickname
if (localStorage.getItem("openid")) { if (localStorage.getItem("openid")) {
this.openid = localStorage.getItem("openid"); this.qqUserInfo.openid = localStorage.getItem("openid");
} }
if (localStorage.getItem("nickname")) { if (localStorage.getItem("access_token")) {
this.nickname = localStorage.getItem("nickname"); this.qqUserInfo.access_token = localStorage.getItem("access_token");
}
if (localStorage.getItem("refresh_token")) {
this.qqUserInfo.refresh_token = localStorage.getItem("refresh_token");
} }
} }
...@@ -195,6 +177,7 @@ ...@@ -195,6 +177,7 @@
/** /**
* 获取url参数 * 获取url参数
* @param name
*/ */
public getUrlParam(name: any) { public getUrlParam(name: any) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
...@@ -220,20 +203,19 @@ ...@@ -220,20 +203,19 @@
if (!validatestate) { if (!validatestate) {
return; return;
} }
// 请求参数
var param: any = this.form; var param: any = this.form;
if (this.code && this.state) { if (this.code && this.state) {
param.code = this.code; param.code = this.code;
param.state = this.state; param.state = this.state;
param.openid = this.openid; param.openid = this.qqUserInfo.openid;
param.nickname = this.nickname; param.nickname = this.qqUserInfo.nickname;
} }else {
else {
this.$message.error("QQ授权,获取code失败"); this.$message.error("QQ授权,获取code失败");
return; return;
} }
// post请求绑定qq
const post: Promise<any> = this.$http.post('/uaa/bindQQtoRegister', param, true); const post: Promise<any> = this.$http.post('/uaa/open/qq/bind', param, true);
post.then((response: any) => { post.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
...@@ -245,13 +227,10 @@ ...@@ -245,13 +227,10 @@
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); const user: any = data.user;
} localStorage.setItem('user', JSON.stringify(user));
if (data.ibzuser) {
let ibzuser: any = data.ibzuser;
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天 // 设置cookie,保存账号密码7天
this.setCookie(ibzuser.loginname, ibzuser.password, 7); this.setCookie("loginname", user.loginname, 7);
// 跳转首页 // 跳转首页
const url: any = '*'; const url: any = '*';
this.$router.push({path: url}); this.$router.push({path: url});
...@@ -278,8 +257,12 @@ ...@@ -278,8 +257,12 @@
}); });
} }
/** /**
* 设置cookie * 设置Cookie
* @param name
* @param value
* @param day
*/ */
public setCookie(name: any, value: any, day: any) { public setCookie(name: any, value: any, day: any) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
...@@ -290,7 +273,7 @@ ...@@ -290,7 +273,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
......
...@@ -62,39 +62,25 @@ ...@@ -62,39 +62,25 @@
}) })
export default class weixinLoginRedirect extends Vue { export default class weixinLoginRedirect extends Vue {
/** // 表单
* 表单对象
*
* @type {*}
* @memberof Register
*/
public form: any = {loginname: '', password: ''}; public form: any = {loginname: '', password: ''};
// 表单可点击
/**
* 按钮可点击
*/
public canClick: any = true; public canClick: any = true;
// 按钮内容
/**
* 按钮内容
*/
public BtnContent: any = "注册并绑定微信"; public BtnContent: any = "注册并绑定微信";
/** // 微信授权成功返回的code和state
* 微信授权成功返回的code和state
*/
public code: any; public code: any;
public state: any; public state: any;
/** // 微信用户信息
* 微信用户身份的唯一标识 public wechatUserInfo:any = {
*/ openid:'',//微信用户身份的唯一标识
public openid: any; nickname:'',//微信用户名称
access_token: '',// 临时授权token
/** refresh_token:'',// 刷新授权token
* 微信用户名称 unionid:'',//微信用户唯一标识
*/ }
public nickname: any;
/** /**
* 应用名称 * 应用名称
...@@ -141,7 +127,6 @@ ...@@ -141,7 +127,6 @@
* 挂载 * 挂载
*/ */
public mounted() { public mounted() {
// 从url获取授权code和state // 从url获取授权code和state
this.code = this.$route.query.code; this.code = this.$route.query.code;
if (!this.code) { if (!this.code) {
...@@ -157,12 +142,18 @@ ...@@ -157,12 +142,18 @@
this.goLogin(); this.goLogin();
} }
else { else {
// 从local中获取该用户的openid和nickname // 从local中获取微信用户的openid,可用于后续请求及绑定操作
if (localStorage.getItem("openid")) { if (localStorage.getItem("openid")) {
this.openid = localStorage.getItem("openid"); this.wechatUserInfo.openid = localStorage.getItem("openid");
} }
if (localStorage.getItem("nickname")) { if (localStorage.getItem("access_token")) {
this.nickname = localStorage.getItem("nickname"); this.wechatUserInfo.access_token = localStorage.getItem("access_token");
}
if (localStorage.getItem("refresh_token")) {
this.wechatUserInfo.refresh_token = localStorage.getItem("refresh_token");
}
if (localStorage.getItem("unionid")) {
this.wechatUserInfo.unionid = localStorage.getItem("unionid");
} }
} }
...@@ -191,6 +182,7 @@ ...@@ -191,6 +182,7 @@
/** /**
* 获取url参数 * 获取url参数
* @param name
*/ */
public getUrlParam(name: any) { public getUrlParam(name: any) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
...@@ -216,20 +208,19 @@ ...@@ -216,20 +208,19 @@
if (!validatestate) { if (!validatestate) {
return; return;
} }
// 请求传参 // 请求传参
var param: any = this.form; var param: any = this.form;
if (this.code && this.state) { if (this.code && this.state) {
param.code = this.code; param.code = this.code;
param.state = this.state; param.state = this.state;
param.openid = this.openid; param.openid = this.wechatUserInfo.openid;
param.nickname = this.nickname; param.nickname = this.wechatUserInfo.nickname;
} else { } else {
this.$message.error("微信授权,获取code失败"); this.$message.error("微信授权,获取code失败");
return; return;
} }
// post请求绑定微信
const post: Promise<any> = this.$http.post('/uaa/bindWechatToRegister', param, true); const post: Promise<any> = this.$http.post('/uaa/open/wechat/bind', param, true);
post.then((response: any) => { post.then((response: any) => {
if (response && response.status === 200) { if (response && response.status === 200) {
const data = response.data; const data = response.data;
...@@ -241,13 +232,10 @@ ...@@ -241,13 +232,10 @@
localStorage.setItem('token', data.token); localStorage.setItem('token', data.token);
} }
if (data.user) { if (data.user) {
localStorage.setItem('user', JSON.stringify(data.user)); let user: any = data.user;
} localStorage.setItem('user',JSON.stringify(user));
if (data.ibzuser) { // 设置cookie,保存账号7天
let ibzuser: any = data.ibzuser; this.setCookie("loginname", user.loginname, 7);
localStorage.setItem('ibzuser',JSON.stringify(ibzuser));
// 设置cookie,保存账号密码7天
this.setCookie(ibzuser.loginname, ibzuser.password, 7);
// 跳转首页 // 跳转首页
const url: any = '*'; const url: any = '*';
this.$router.push({path: url}); this.$router.push({path: url});
...@@ -274,8 +262,12 @@ ...@@ -274,8 +262,12 @@
}); });
} }
/** /**
* 设置cookie * 设置Cookie
* @param name
* @param value
* @param day
*/ */
public setCookie(name: any, value: any, day: any) { public setCookie(name: any, value: any, day: any) {
if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除 if (day !== 0) { //当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
...@@ -286,7 +278,7 @@ ...@@ -286,7 +278,7 @@
var leftTamp = 24 * 60 * 60 * 1000 - passedTamp; var leftTamp = 24 * 60 * 60 * 1000 - passedTamp;
var leftTime = new Date(); var leftTime = new Date();
leftTime.setTime(leftTamp + curTamp); leftTime.setTime(leftTamp + curTamp);
document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString(); document.cookie = name + "=" + escape(value) + ";expires=" + leftTime.toUTCString() + ";path=/";
} else { } else {
document.cookie = name + "=" + escape(value); document.cookie = name + "=" + escape(value);
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册