提交 7ff24fb9 编写于 作者: laizhilong's avatar laizhilong

第三方注册时创建用户授权信息

上级 0222cbcc
...@@ -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)) {
// 钉钉授权code已失效,重新授权
throw new BadRequestAlertException("钉钉授权已失效,请重新授权","UserDingtalkRegisterResource","");
} else {
// 已经有钉钉用户信息直接注册
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password); ibzuser.setPassword(password);
ibzuser.setLoginname(loginname); ibzuser.setLoginname(loginname);
ibzuser.setUserid("dingtalk-" + uuid); ibzuser.setUserid("dingtalk-" + uuid);
ibzuser.setPersonname(nickname); ibzuser.setPersonname(nickname);
ibzuser.setNickname(nickname); ibzuser.setNickname(nickname);
ibzuser.setAvatar(openid);
userDingtalkRegisterService.toRegister(ibzuser); userDingtalkRegisterService.toRegister(ibzuser);
} // 创建钉钉用户授权信息
SysUserAuth userAuth = new SysUserAuth();
userAuth.setUserid(ibzuser.getUserid());
userAuth.setIdentifier(openid);
userAuth.setIdentityType("dingtalk");
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)) {
// 通过code获取微信用户信息
JSONObject returnObj = userQQRegisterService.requestQQUserByCode(code, qqRedirectUri, qqAppId, qqAppKey);
if (!StringUtils.isEmpty(returnObj)) {
if (returnObj.containsKey("openid")) {
// 微信注册
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password); ibzuser.setPassword(password);
ibzuser.setLoginname(loginname); ibzuser.setLoginname(loginname);
ibzuser.setUserid("tencent-" + uuid); ibzuser.setUserid("qq-" + uuid);
ibzuser.setPersonname(returnObj.getString("nickname"));
ibzuser.setNickname(returnObj.getString("nickname"));
ibzuser.setAvatar(returnObj.getString("openid"));
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.setPersonname(nickname);
ibzuser.setNickname(nickname); ibzuser.setNickname(nickname);
ibzuser.setAvatar(openid);
userQQRegisterService.toRegister(ibzuser); userQQRegisterService.toRegister(ibzuser);
} // 创建QQ用户授权信息
SysUserAuth userAuth = new SysUserAuth();
userAuth.setUserid(ibzuser.getUserid());
userAuth.setIdentifier(openid);
userAuth.setIdentityType("qq");
userQQRegisterService.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.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)) {
// 通过code获取微信用户信息
JSONObject returnObj = userWechatRegisterService.requestWechatUserByCode(code, null, WechatAppid, WechatAppsecret);
if (!StringUtils.isEmpty(returnObj)) {
if (returnObj.containsKey("openid")) {
// 微信注册
String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password);
ibzuser.setLoginname(loginname);
ibzuser.setUserid("wechat-" + uuid);
ibzuser.setPersonname(returnObj.getString("nickname"));
ibzuser.setNickname(returnObj.getString("nickname"));
ibzuser.setAvatar(returnObj.getString("openid"));
userWechatRegisterService.toRegister(ibzuser);
} else {
throw new BadRequestAlertException("获取微信授权用户相关信息失败!", "UserWechatRegisterResource", "");
}
} else {
throw new BadRequestAlertException("获取微信授权用户相关信息失败!", "UserWechatRegisterResource", "");
}
} else {
// 已经有微信用户信息直接注册
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
ibzuser.setPassword(password); ibzuser.setPassword(password);
ibzuser.setLoginname(loginname); ibzuser.setLoginname(loginname);
ibzuser.setUserid("wechat-" + uuid); ibzuser.setUserid("wechat-" + uuid);
ibzuser.setPersonname(nickname); ibzuser.setPersonname(nickname);
ibzuser.setNickname(nickname); ibzuser.setNickname(nickname);
ibzuser.setAvatar(openid);
userWechatRegisterService.toRegister(ibzuser); userWechatRegisterService.toRegister(ibzuser);
} // 创建微信用户授权信息
SysUserAuth userAuth = new SysUserAuth();
userAuth.setUserid(ibzuser.getUserid());
userAuth.setIdentifier(openid);
userAuth.setIdentityType("wechat");
userWechatRegisterService.toCreateUserAuth(userAuth);
// 注册成功,登录系统 // 注册成功,登录系统
if (!StringUtils.isEmpty(ibzuser)) { if (!StringUtils.isEmpty(ibzuser)) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册