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

Merge remote-tracking branch 'origin/master'

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