|
@@ -27,12 +27,14 @@ import cn.iocoder.byzs.module.system.service.member.MemberService;
|
|
|
import cn.iocoder.byzs.module.system.service.oauth2.OAuth2TokenService;
|
|
import cn.iocoder.byzs.module.system.service.oauth2.OAuth2TokenService;
|
|
|
import cn.iocoder.byzs.module.system.service.social.SocialUserService;
|
|
import cn.iocoder.byzs.module.system.service.social.SocialUserService;
|
|
|
import cn.iocoder.byzs.module.system.service.user.AdminUserService;
|
|
import cn.iocoder.byzs.module.system.service.user.AdminUserService;
|
|
|
|
|
+import cn.iocoder.byzs.module.system.util.IpUtil;
|
|
|
import com.anji.captcha.model.common.ResponseModel;
|
|
import com.anji.captcha.model.common.ResponseModel;
|
|
|
import com.anji.captcha.model.vo.CaptchaVO;
|
|
import com.anji.captcha.model.vo.CaptchaVO;
|
|
|
import com.anji.captcha.service.CaptchaService;
|
|
import com.anji.captcha.service.CaptchaService;
|
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
import jakarta.validation.Validator;
|
|
import jakarta.validation.Validator;
|
|
|
|
|
+import jodd.util.StringUtil;
|
|
|
import lombok.Setter;
|
|
import lombok.Setter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -115,10 +117,42 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
|
|
reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
|
|
reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 校验登录ip是否已被授权
|
|
|
|
|
+ validateLongIp(user);
|
|
|
|
|
+
|
|
|
// 创建 Token 令牌,记录登录日志
|
|
// 创建 Token 令牌,记录登录日志
|
|
|
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
|
|
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ //判断是否需要校验验证码
|
|
|
|
|
+ private void validateLongIp(AdminUserDO user) {
|
|
|
|
|
+
|
|
|
|
|
+ // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
+ if (!Objects.equals(TenantContextHolder.getTenantId(), WebFrameworkUtils.DEFAULT_TENANT_ID)){
|
|
|
|
|
+
|
|
|
|
|
+ //校验手机号是否存在
|
|
|
|
|
+ if(StringUtil.isBlank(user.getMobile())){
|
|
|
|
|
+ throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED_NOT_MOBILE_NOT_EXISTS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //查看登录ip是否已被授权
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtil.isNotBlank(user.getLoginIp()) && !IpUtil.isSameNetworkSegment(user.getLoginIp(), getClientIP())) {
|
|
|
|
|
+
|
|
|
|
|
+ //发送手机验证码
|
|
|
|
|
+// AuthSmsLoginReqVO authSmsLoginReqVO = new AuthSmsLoginReqVO().setMobile(user.getNickname());
|
|
|
|
|
+// smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(authSmsLoginReqVO));
|
|
|
|
|
+
|
|
|
|
|
+ throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
+ oauth2TokenService.removeUserTokens(user.getId(), getUserType().getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void sendSmsCode(AuthSmsSendReqVO reqVO) {
|
|
public void sendSmsCode(AuthSmsSendReqVO reqVO) {
|
|
|
// 如果是重置密码场景,需要校验图形验证码是否正确
|
|
// 如果是重置密码场景,需要校验图形验证码是否正确
|
|
@@ -214,24 +248,6 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
|
|
|
|
|
|
|
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
|
private AuthLoginRespVO createTokenAfterLoginSuccess(Long userId, String username, LoginLogTypeEnum logType) {
|
|
|
|
|
|
|
|
- // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
- if (!Objects.equals(TenantContextHolder.getTenantId(), WebFrameworkUtils.DEFAULT_TENANT_ID)){
|
|
|
|
|
- // 删除用户之前的所有令牌,实现单点登录(默认租户用户可以多设备登录)
|
|
|
|
|
- oauth2TokenService.removeUserTokens(userId, getUserType().getValue());
|
|
|
|
|
-
|
|
|
|
|
- //查看登录ip是否已被授权
|
|
|
|
|
- Set<String> userLoginIpSet = loginLogService.selectIpListByUserId(userId);
|
|
|
|
|
- if(!userLoginIpSet.contains(ServletUtils.getClientIP())){
|
|
|
|
|
-
|
|
|
|
|
- //需要手机号校验
|
|
|
|
|
- //发送手机验证码
|
|
|
|
|
- AuthSmsLoginReqVO authSmsLoginReqVO = new AuthSmsLoginReqVO().setMobile(username);
|
|
|
|
|
-// smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(authSmsLoginReqVO));
|
|
|
|
|
-
|
|
|
|
|
- throw exception(AUTH_LOGIN_IP_NOT_AUTHORIZED);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
// 插入登陆日志
|
|
// 插入登陆日志
|
|
|
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
|
|
createLoginLog(userId, username, logType, LoginResultEnum.SUCCESS);
|
|
|
|
|
|