mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-14 22:29:00 +08:00
♻️ Refactoring code. 修改社交登录绑定逻辑,增加去重判断
This commit is contained in:
1 parent
fe191320e3
commit
e461af354e
7 files changed
+139
-26
No files matched your search
+28
-2
@@ -17,6 +17,10 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
@@ -34,8 +38,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/4/8
|
||||
@@ -97,4 +99,28 @@ public class GiteeLoginHandler extends AbstractLoginHandler {
|
||||
return sysUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
List<SysUser> userList = sysUserService
|
||||
.list(Wrappers.<SysUser>query().lambda().eq(SysUser::getGiteeLogin, identify));
|
||||
|
||||
// 先把原有绑定关系去除,设置绑定为NULL
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setGiteeLogin(identify);
|
||||
sysUserService.update(condition, Wrappers.<SysUser>lambdaUpdate().set(SysUser::getGiteeLogin, null));
|
||||
log.info("码云账号 {} 更换账号绑定", identify);
|
||||
}
|
||||
|
||||
user.setGiteeLogin(identify);
|
||||
sysUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -18,6 +18,7 @@
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysUser;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -55,4 +56,12 @@ public interface LoginHandler {
|
||||
*/
|
||||
UserInfo handle(String loginStr);
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
Boolean bind(SysUser user, String identify);
|
||||
|
||||
}
|
||||
+27
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -85,4 +88,28 @@ public class MiniAppLoginHandler extends AbstractLoginHandler {
|
||||
return sysUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
List<SysUser> userList = sysUserService
|
||||
.list(Wrappers.<SysUser>query().lambda().eq(SysUser::getMiniOpenid, identify));
|
||||
|
||||
// 先把原有绑定关系去除,设置绑定为NULL
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setMiniOpenid(identify);
|
||||
sysUserService.update(condition, Wrappers.<SysUser>lambdaUpdate().set(SysUser::getMiniOpenid, null));
|
||||
log.info("小程序账号 {} 更换账号绑定", identify);
|
||||
}
|
||||
|
||||
user.setMiniOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+29
-3
@@ -17,6 +17,11 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
@@ -33,9 +38,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2019/4/8
|
||||
@@ -105,4 +107,28 @@ public class OscChinaLoginHandler extends AbstractLoginHandler {
|
||||
return sysUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
List<SysUser> userList = sysUserService
|
||||
.list(Wrappers.<SysUser>query().lambda().eq(SysUser::getOscId, identify));
|
||||
|
||||
// 先把原有绑定关系去除,设置绑定为NULL
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setOscId(identify);
|
||||
sysUserService.update(condition, Wrappers.<SysUser>lambdaUpdate().set(SysUser::getOscId, null));
|
||||
log.info("开源中国账号 {} 更换账号绑定", identify);
|
||||
}
|
||||
|
||||
user.setOscId(identify);
|
||||
sysUserService.updateById(user);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+13
@@ -62,4 +62,17 @@ public class SmsLoginHandler extends AbstractLoginHandler {
|
||||
return sysUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
user.setGiteeLogin(identify);
|
||||
sysUserService.updateById(user);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -17,6 +17,9 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.handler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -83,4 +86,28 @@ public class WeChatLoginHandler extends AbstractLoginHandler {
|
||||
return sysUserService.findUserInfo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定逻辑
|
||||
* @param user 用户实体
|
||||
* @param identify 渠道返回唯一标识
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(SysUser user, String identify) {
|
||||
List<SysUser> userList = sysUserService
|
||||
.list(Wrappers.<SysUser>query().lambda().eq(SysUser::getWxOpenid, identify));
|
||||
|
||||
// 先把原有绑定关系去除,设置绑定为NULL
|
||||
if (CollUtil.isNotEmpty(userList)) {
|
||||
SysUser condition = new SysUser();
|
||||
condition.setWxOpenid(identify);
|
||||
sysUserService.update(condition, Wrappers.<SysUser>lambdaUpdate().set(SysUser::getWxOpenid, null));
|
||||
log.info("微信账号 {} 更换账号绑定", identify);
|
||||
}
|
||||
|
||||
user.setWxOpenid(identify);
|
||||
sysUserService.updateById(user);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-21
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.pig4cloud.pigx.admin.service.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
|
||||
@@ -27,15 +29,12 @@ import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper;
|
||||
import com.pig4cloud.pigx.admin.mapper.SysUserMapper;
|
||||
import com.pig4cloud.pigx.admin.service.SysSocialDetailsService;
|
||||
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
|
||||
import com.pig4cloud.pigx.common.core.constant.enums.LoginTypeEnum;
|
||||
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018年08月16日
|
||||
@@ -60,26 +59,12 @@ public class SysSocialDetailsServiceImpl extends ServiceImpl<SysSocialDetailsMap
|
||||
*/
|
||||
@Override
|
||||
public Boolean bindSocial(String type, String code) {
|
||||
String identify = loginHandlerMap.get(type).identify(code);
|
||||
LoginHandler loginHandler = loginHandlerMap.get(type);
|
||||
// 绑定逻辑
|
||||
String identify = loginHandler.identify(code);
|
||||
SysUser sysUser = sysUserMapper.selectById(SecurityUtils.getUser().getId());
|
||||
loginHandler.bind(sysUser, identify);
|
||||
|
||||
if (LoginTypeEnum.GITEE.getType().equals(type)) {
|
||||
sysUser.setGiteeLogin(identify);
|
||||
}
|
||||
else if (LoginTypeEnum.OSC.getType().equals(type)) {
|
||||
sysUser.setOscId(identify);
|
||||
}
|
||||
else if (LoginTypeEnum.WECHAT.getType().equals(type)) {
|
||||
sysUser.setWxOpenid(identify);
|
||||
}
|
||||
else if (LoginTypeEnum.QQ.getType().equals(type)) {
|
||||
sysUser.setQqOpenid(identify);
|
||||
}
|
||||
else if (LoginTypeEnum.MINI_APP.getType().equals(type)) {
|
||||
sysUser.setMiniOpenid(identify);
|
||||
}
|
||||
|
||||
sysUserMapper.updateById(sysUser);
|
||||
// 更新緩存
|
||||
cacheManager.getCache(CacheConstants.USER_DETAILS).evict(sysUser.getUsername());
|
||||
return Boolean.TRUE;
|
||||
|
||||
Reference in new issue
Block a user