提交 214af11f 编写于 作者: sq3536's avatar sq3536

Merge remote-tracking branch 'origin/master'

...@@ -266,6 +266,8 @@ ...@@ -266,6 +266,8 @@
closable: true closable: true
}); });
} }
// 返回登录页
this.goLogin();
}); });
} }
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
<span class="form_tipinfo">其他登录方式</span> <span class="form_tipinfo">其他登录方式</span>
</div> </div>
<div style="text-align: center"> <div style="text-align: center">
<div class="sign-btn" @click="tencentHandleClick('tencent')"> <div class="sign-btn" @click="qqHandleClick('qq')">
<img src="/assets/img/QQ.svg" class="qq-svg-container" draggable="false"> <img src="/assets/img/QQ.svg" class="qq-svg-container" draggable="false">
</div> </div>
<div class="sign-btn" @click="wechatHandleClick('wechat')"> <div class="sign-btn" @click="wechatHandleClick('wechat')">
...@@ -258,7 +258,7 @@ ...@@ -258,7 +258,7 @@
* qq授权登录 * qq授权登录
* @param thirdpart * @param thirdpart
*/ */
public tencentHandleClick(thirdpart: any) { public qqHandleClick(thirdpart: any) {
// 截取地址,拼接需要部分组成新地址 // 截取地址,拼接需要部分组成新地址
const baseUrl = this.getNeedLocation(); const baseUrl = this.getNeedLocation();
......
...@@ -272,63 +272,11 @@ ...@@ -272,63 +272,11 @@
closable: true closable: true
}); });
} }
// 返回登录页
this.goLogin();
}); });
} }
/**
* 自动登录倒计时
*/
public countDown(totalTime: any): void {
if (!this.canClick) return;
this.canClick = false;
this.BtnContent = totalTime + 's后自动登录';
// 设置定时器
let clock = window.setInterval(() => {
// 秒数-1
totalTime--;
this.BtnContent = totalTime + 's后自动登录';
if (totalTime < 0) {
// 清除定时器
window.clearInterval(clock);
// 登录请求
const loginname: any = this.form.loginname;
const password: any = this.form.password;
const post: Promise<any> = this.$http.post('v7/login', this.form, true);
post.then((response: any) => {
if (response && response.status === 200) {
const data = response.data;
if (data && data.token) {
localStorage.setItem('token', data.token);
}
if (data && data.user) {
localStorage.setItem('user', JSON.stringify(data.user));
}
// 设置cookie,保存账号密码7天
this.setCookie(loginname, password, 7);
// 跳转首页
const url: any = this.$route.query.redirect ? this.$route.query.redirect : '*';
this.$router.push({path: url});
}
}).catch((error: any) => {
const data = error.data;
if (data && data.detail) {
this.$Message.error({
content: "登录失败," + data.detail,
duration: 3,
closable: true
});
} else {
this.$Message.error({
content: "登录失败",
duration: 3,
closable: true
});
}
});
}
}, 1000)
}
/** /**
......
...@@ -268,6 +268,8 @@ ...@@ -268,6 +268,8 @@
closable: true closable: true
}); });
} }
// 返回登录页
this.goLogin();
}); });
} }
......
package cn.ibizlab.core.uaa.extensions.service; package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.service.IBZUSERService; import cn.ibizlab.util.service.IBZUSERService;
...@@ -33,7 +35,8 @@ public class UserDingtalkRegisterService { ...@@ -33,7 +35,8 @@ public class UserDingtalkRegisterService {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
/** /**
* 注册 * 注册
...@@ -48,6 +51,18 @@ public class UserDingtalkRegisterService { ...@@ -48,6 +51,18 @@ public class UserDingtalkRegisterService {
} }
} }
/**
* 创建钉钉用户授权信息
* @param userAuth
*/
public void toCreateUserAuth(SysUserAuth userAuth) {
// 创建用户授权信息
boolean flag = sysUserAuthService.create(userAuth);
if (!flag) {
throw new BadRequestAlertException("保存用户授权信息失败", "UserDingtalkRegisterService", "");
}
}
/** /**
* 钉钉服务端通过临时授权码code获取授权用户的个人信息 * 钉钉服务端通过临时授权码code获取授权用户的个人信息
...@@ -72,7 +87,7 @@ public class UserDingtalkRegisterService { ...@@ -72,7 +87,7 @@ public class UserDingtalkRegisterService {
// 通过临时授权码Code获取用户信息,临时授权码只能使用一次 // 通过临时授权码Code获取用户信息,临时授权码只能使用一次
String url = "https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=" + dingTalkAppId String url = "https://oapi.dingtalk.com/sns/getuserinfo_bycode?accessKey=" + dingTalkAppId
+ "&timestamp=" + String.valueOf(currentTimeMillis) + "&timestamp=" + currentTimeMillis
+ "&signature=" + urlEncodeSignature; + "&signature=" + urlEncodeSignature;
// 创建httpclient对象 // 创建httpclient对象
......
package cn.ibizlab.core.uaa.extensions.service; package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.HttpUtils; import cn.ibizlab.util.helper.HttpUtils;
...@@ -21,7 +23,8 @@ public class UserQQRegisterService { ...@@ -21,7 +23,8 @@ public class UserQQRegisterService {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
/** /**
* 注册 * 注册
...@@ -36,6 +39,17 @@ public class UserQQRegisterService { ...@@ -36,6 +39,17 @@ public class UserQQRegisterService {
} }
} }
/**
* 创建QQ用户授权信息
* @param ibzuser
*/
public void toCreateUserAuth(SysUserAuth ibzuser) {
// 创建用户授权信息
boolean flag = sysUserAuthService.create(ibzuser);
if (!flag) {
throw new BadRequestAlertException("保存用户授权信息失败", "UserQQRegisterService", "");
}
}
/** /**
* 通过code获取QQ用户信息 * 通过code获取QQ用户信息
...@@ -112,4 +126,5 @@ public class UserQQRegisterService { ...@@ -112,4 +126,5 @@ public class UserQQRegisterService {
} }
} }
\ No newline at end of file
package cn.ibizlab.core.uaa.extensions.service; package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.HttpUtils; import cn.ibizlab.util.helper.HttpUtils;
...@@ -21,7 +23,8 @@ public class UserWechatRegisterService { ...@@ -21,7 +23,8 @@ public class UserWechatRegisterService {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired
private ISysUserAuthService sysUserAuthService;
/** /**
* 注册 * 注册
...@@ -37,6 +40,18 @@ public class UserWechatRegisterService { ...@@ -37,6 +40,18 @@ public class UserWechatRegisterService {
} }
/**
* 创建微信用户授权信息
* @param userAuth
*/
public void toCreateUserAuth(SysUserAuth userAuth) {
// 创建用户授权信息
boolean flag = sysUserAuthService.create(userAuth);
if (!flag) {
throw new BadRequestAlertException("保存用户授权信息失败", "UserWechatRegisterService", "");
}
}
/** /**
* 通过code获取微信用户信息 * 通过code获取微信用户信息
* *
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserDingtalkRegisterService; import cn.ibizlab.core.uaa.extensions.service.UserDingtalkRegisterService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
...@@ -32,6 +34,8 @@ public class UserDingtalkRegisterResource { ...@@ -32,6 +34,8 @@ public class UserDingtalkRegisterResource {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired @Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private AuthTokenUtil jwtTokenUtil; private AuthTokenUtil jwtTokenUtil;
@Autowired @Autowired
@Qualifier("UAAUserService") @Qualifier("UAAUserService")
...@@ -83,11 +87,12 @@ public class UserDingtalkRegisterResource { ...@@ -83,11 +87,12 @@ public class UserDingtalkRegisterResource {
object.put("nickname", nickname); object.put("nickname", nickname);
} }
//根据openid查用户 // 根据openid查用户授权信息
List<IBZUSER> ibzusers = ibzuserService.list(Wrappers.<IBZUSER>query().eq("avatar", openid)); List<SysUserAuth> sysUserAuths = sysUserAuthService.list(Wrappers.<SysUserAuth>query().eq("identifier", openid));
// 该钉钉用户注册过账号,登录系统 // 该钉钉用户注册过账号,登录系统
if (ibzusers.size() > 0) { if (sysUserAuths.size()>0) {
IBZUSER ibzuser = ibzusers.get(0); SysUserAuth userauth = sysUserAuths.get(0);
IBZUSER ibzuser = ibzuserService.getById(userauth.getUserid());
object.put("ibzuser", ibzuser); object.put("ibzuser", ibzuser);
// 生成登录token信息 // 生成登录token信息
...@@ -129,26 +134,22 @@ public class UserDingtalkRegisterResource { ...@@ -129,26 +134,22 @@ public class UserDingtalkRegisterResource {
if (StringUtils.isEmpty(nickname)) if (StringUtils.isEmpty(nickname))
throw new BadRequestAlertException("钉钉信息nickname为空", "UserDingtalkRegisterResource", ""); throw new BadRequestAlertException("钉钉信息nickname为空", "UserDingtalkRegisterResource", "");
// 检查用户名是否已被注册 // 钉钉用户注册
List<IBZUSER> ibzusers = ibzuserService.list(Wrappers.<IBZUSER>query().eq("loginname", loginname));
if (ibzusers.size() > 0)
throw new BadRequestAlertException("该用户名已被注册", "UserDingtalkRegisterResource", "");
IBZUSER ibzuser = new IBZUSER(); IBZUSER ibzuser = new IBZUSER();
if (StringUtils.isEmpty(openid)) { String uuid = UUID.randomUUID().toString();
// 钉钉授权code已失效,重新授权 ibzuser.setPassword(password);
throw new BadRequestAlertException("钉钉授权已失效,请重新授权","UserDingtalkRegisterResource",""); ibzuser.setLoginname(loginname);
} else { ibzuser.setUserid("dingtalk-" + uuid);
// 已经有钉钉用户信息直接注册 ibzuser.setPersonname(nickname);
String uuid = UUID.randomUUID().toString(); ibzuser.setNickname(nickname);
ibzuser.setPassword(password); userDingtalkRegisterService.toRegister(ibzuser);
ibzuser.setLoginname(loginname); // 创建钉钉用户授权信息
ibzuser.setUserid("dingtalk-" + uuid); SysUserAuth userAuth = new SysUserAuth();
ibzuser.setPersonname(nickname); userAuth.setUserid(ibzuser.getUserid());
ibzuser.setNickname(nickname); userAuth.setIdentifier(openid);
ibzuser.setAvatar(openid); userAuth.setIdentityType("dingtalk");
userDingtalkRegisterService.toRegister(ibzuser); userDingtalkRegisterService.toCreateUserAuth(userAuth);
}
// 注册成功,登录系统 // 注册成功,登录系统
if (!StringUtils.isEmpty(ibzuser)) { if (!StringUtils.isEmpty(ibzuser)) {
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserQQRegisterService; import cn.ibizlab.core.uaa.extensions.service.UserQQRegisterService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
...@@ -32,6 +34,8 @@ public class UserQQRegisterResource { ...@@ -32,6 +34,8 @@ public class UserQQRegisterResource {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired @Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private AuthTokenUtil jwtTokenUtil; private AuthTokenUtil jwtTokenUtil;
@Autowired @Autowired
@Qualifier("UAAUserService") @Qualifier("UAAUserService")
...@@ -84,11 +88,12 @@ public class UserQQRegisterResource { ...@@ -84,11 +88,12 @@ public class UserQQRegisterResource {
object.put("nickname", nickname); object.put("nickname", nickname);
} }
//根据openid查用户 // 根据openid查用户授权信息
List<IBZUSER> ibzusers = ibzuserService.list(Wrappers.<IBZUSER>query().eq("avatar", openid)); List<SysUserAuth> sysUserAuths = sysUserAuthService.list(Wrappers.<SysUserAuth>query().eq("identifier", openid));
// 该QQ用户注册过账号,登录系统 // 该QQ用户注册过账号,登录系统
if (ibzusers.size() > 0) { if (sysUserAuths.size()>0) {
IBZUSER ibzuser = ibzusers.get(0); SysUserAuth userauth = sysUserAuths.get(0);
IBZUSER ibzuser = ibzuserService.getById(userauth.getUserid());
object.put("ibzuser", ibzuser); object.put("ibzuser", ibzuser);
// 生成登录token信息 // 生成登录token信息
...@@ -142,38 +147,21 @@ public class UserQQRegisterResource { ...@@ -142,38 +147,21 @@ public class UserQQRegisterResource {
if (ibzusers.size() > 0) if (ibzusers.size() > 0)
throw new BadRequestAlertException("该用户名已被注册", "UserQQRegisterResource", ""); throw new BadRequestAlertException("该用户名已被注册", "UserQQRegisterResource", "");
// QQ用户注册
IBZUSER ibzuser = new IBZUSER(); IBZUSER ibzuser = new IBZUSER();
if (StringUtils.isEmpty(openid)) { String uuid = UUID.randomUUID().toString();
// 通过code获取微信用户信息 ibzuser.setPassword(password);
JSONObject returnObj = userQQRegisterService.requestQQUserByCode(code, qqRedirectUri, qqAppId, qqAppKey); ibzuser.setLoginname(loginname);
if (!StringUtils.isEmpty(returnObj)) { ibzuser.setUserid("qq-" + uuid);
if (returnObj.containsKey("openid")) { ibzuser.setPersonname(nickname);
// 微信注册 ibzuser.setNickname(nickname);
String uuid = UUID.randomUUID().toString(); userQQRegisterService.toRegister(ibzuser);
ibzuser.setPassword(password); // 创建QQ用户授权信息
ibzuser.setLoginname(loginname); SysUserAuth userAuth = new SysUserAuth();
ibzuser.setUserid("tencent-" + uuid); userAuth.setUserid(ibzuser.getUserid());
ibzuser.setPersonname(returnObj.getString("nickname")); userAuth.setIdentifier(openid);
ibzuser.setNickname(returnObj.getString("nickname")); userAuth.setIdentityType("qq");
ibzuser.setAvatar(returnObj.getString("openid")); userQQRegisterService.toCreateUserAuth(userAuth);
userQQRegisterService.toRegister(ibzuser);
} else {
throw new BadRequestAlertException("获取QQ授权用户相关信息失败!", "UserQQRegisterResource", "");
}
} else {
throw new BadRequestAlertException("获取QQ授权用户相关信息失败!", "UserQQRegisterResource", "");
}
} else {
// 已经有微信用户信息直接注册
String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setUserid("tencent-" + uuid);
ibzuser.setPersonname(nickname);
ibzuser.setNickname(nickname);
ibzuser.setAvatar(openid);
userQQRegisterService.toRegister(ibzuser);
}
// 注册成功,登录系统 // 注册成功,登录系统
if (!StringUtils.isEmpty(ibzuser)) { if (!StringUtils.isEmpty(ibzuser)) {
......
package cn.ibizlab.api.rest.extensions; package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.core.uaa.domain.SysUserAuth;
import cn.ibizlab.core.uaa.extensions.service.UserWechatRegisterService; import cn.ibizlab.core.uaa.extensions.service.UserWechatRegisterService;
import cn.ibizlab.core.uaa.service.ISysUserAuthService;
import cn.ibizlab.util.domain.IBZUSER; import cn.ibizlab.util.domain.IBZUSER;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.CachedBeanCopier; import cn.ibizlab.util.helper.CachedBeanCopier;
...@@ -32,6 +34,8 @@ public class UserWechatRegisterResource { ...@@ -32,6 +34,8 @@ public class UserWechatRegisterResource {
@Autowired @Autowired
private IBZUSERService ibzuserService; private IBZUSERService ibzuserService;
@Autowired @Autowired
private ISysUserAuthService sysUserAuthService;
@Autowired
private AuthTokenUtil jwtTokenUtil; private AuthTokenUtil jwtTokenUtil;
@Autowired @Autowired
@Qualifier("UAAUserService") @Qualifier("UAAUserService")
...@@ -83,11 +87,12 @@ public class UserWechatRegisterResource { ...@@ -83,11 +87,12 @@ public class UserWechatRegisterResource {
object.put("nickname", nickname); object.put("nickname", nickname);
} }
//根据openid查用户 // 根据openid查用户授权信息
List<IBZUSER> ibzusers = ibzuserService.list(Wrappers.<IBZUSER>query().eq("avatar", openid)); List<SysUserAuth> sysUserAuths = sysUserAuthService.list(Wrappers.<SysUserAuth>query().eq("identifier", openid));
// 该微信用户注册过账号,登录系统 // 该微信用户注册过账号,登录系统
if (ibzusers.size() > 0) { if (sysUserAuths.size()>0) {
IBZUSER ibzuser = ibzusers.get(0); SysUserAuth userauth = sysUserAuths.get(0);
IBZUSER ibzuser = ibzuserService.getById(userauth.getUserid());
object.put("ibzuser", ibzuser); object.put("ibzuser", ibzuser);
// 生成登录token信息 // 生成登录token信息
...@@ -102,6 +107,7 @@ public class UserWechatRegisterResource { ...@@ -102,6 +107,7 @@ public class UserWechatRegisterResource {
object.put("user", user2); object.put("user", user2);
} }
return ResponseEntity.ok().body(object); return ResponseEntity.ok().body(object);
} }
...@@ -141,38 +147,21 @@ public class UserWechatRegisterResource { ...@@ -141,38 +147,21 @@ public class UserWechatRegisterResource {
if (ibzusers.size() > 0) if (ibzusers.size() > 0)
throw new BadRequestAlertException("该用户名已被注册", "UserWechatRegisterResource", ""); throw new BadRequestAlertException("该用户名已被注册", "UserWechatRegisterResource", "");
// 微信用户注册
IBZUSER ibzuser = new IBZUSER(); IBZUSER ibzuser = new IBZUSER();
if (StringUtils.isEmpty(openid)) { String uuid = UUID.randomUUID().toString();
// 通过code获取微信用户信息 ibzuser.setPassword(password);
JSONObject returnObj = userWechatRegisterService.requestWechatUserByCode(code, null, WechatAppid, WechatAppsecret); ibzuser.setLoginname(loginname);
if (!StringUtils.isEmpty(returnObj)) { ibzuser.setUserid("wechat-" + uuid);
if (returnObj.containsKey("openid")) { ibzuser.setPersonname(nickname);
// 微信注册 ibzuser.setNickname(nickname);
String uuid = UUID.randomUUID().toString(); userWechatRegisterService.toRegister(ibzuser);
ibzuser.setPassword(password); // 创建微信用户授权信息
ibzuser.setLoginname(loginname); SysUserAuth userAuth = new SysUserAuth();
ibzuser.setUserid("wechat-" + uuid); userAuth.setUserid(ibzuser.getUserid());
ibzuser.setPersonname(returnObj.getString("nickname")); userAuth.setIdentifier(openid);
ibzuser.setNickname(returnObj.getString("nickname")); userAuth.setIdentityType("wechat");
ibzuser.setAvatar(returnObj.getString("openid")); userWechatRegisterService.toCreateUserAuth(userAuth);
userWechatRegisterService.toRegister(ibzuser);
} else {
throw new BadRequestAlertException("获取微信授权用户相关信息失败!", "UserWechatRegisterResource", "");
}
} else {
throw new BadRequestAlertException("获取微信授权用户相关信息失败!", "UserWechatRegisterResource", "");
}
} else {
// 已经有微信用户信息直接注册
String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setUserid("wechat-" + uuid);
ibzuser.setPersonname(nickname);
ibzuser.setNickname(nickname);
ibzuser.setAvatar(openid);
userWechatRegisterService.toRegister(ibzuser);
}
// 注册成功,登录系统 // 注册成功,登录系统
if (!StringUtils.isEmpty(ibzuser)) { if (!StringUtils.isEmpty(ibzuser)) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册