Commit e842d2e0ad4bd09379afa672ccb03714d02a9268

Authored by xingyu
1 parent 21ccd3cb

AJ-Captcha 增加验证码二次校验

yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/AuthLoginReqVO.java
@@ -33,6 +33,10 @@ public class AuthLoginReqVO { @@ -33,6 +33,10 @@ public class AuthLoginReqVO {
33 @Length(min = 4, max = 16, message = "密码长度为 4-16 位") 33 @Length(min = 4, max = 16, message = "密码长度为 4-16 位")
34 private String password; 34 private String password;
35 35
  36 + @ApiModelProperty(value = "验证码", required = true, example = "PfcH6mgr8tpXuMWFjvW6YVaqrswIuwmWI5dsVZSg7sGpWtDCUbHuDEXl3cFB1+VvCC/rAkSwK8Fad52FSuncVg==")
  37 + @NotEmpty(message = "验证码不能为空")
  38 + private String captchaVerification;
  39 +
36 // ========== 绑定社交登录时,需要传递如下参数 ========== 40 // ========== 绑定社交登录时,需要传递如下参数 ==========
37 41
38 @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") 42 @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值")
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
@@ -21,6 +21,9 @@ import cn.iocoder.yudao.module.system.service.member.MemberService; @@ -21,6 +21,9 @@ import cn.iocoder.yudao.module.system.service.member.MemberService;
21 import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService; 21 import cn.iocoder.yudao.module.system.service.oauth2.OAuth2TokenService;
22 import cn.iocoder.yudao.module.system.service.social.SocialUserService; 22 import cn.iocoder.yudao.module.system.service.social.SocialUserService;
23 import cn.iocoder.yudao.module.system.service.user.AdminUserService; 23 import cn.iocoder.yudao.module.system.service.user.AdminUserService;
  24 +import com.anji.captcha.model.common.ResponseModel;
  25 +import com.anji.captcha.model.vo.CaptchaVO;
  26 +import com.anji.captcha.service.CaptchaService;
24 import lombok.extern.slf4j.Slf4j; 27 import lombok.extern.slf4j.Slf4j;
25 import org.springframework.stereotype.Service; 28 import org.springframework.stereotype.Service;
26 29
@@ -51,10 +54,10 @@ public class AdminAuthServiceImpl implements AdminAuthService { @@ -51,10 +54,10 @@ public class AdminAuthServiceImpl implements AdminAuthService {
51 private SocialUserService socialUserService; 54 private SocialUserService socialUserService;
52 @Resource 55 @Resource
53 private MemberService memberService; 56 private MemberService memberService;
54 -  
55 @Resource 57 @Resource
56 private Validator validator; 58 private Validator validator;
57 - 59 + @Resource
  60 + private CaptchaService captchaService;
58 @Resource 61 @Resource
59 private SmsCodeApi smsCodeApi; 62 private SmsCodeApi smsCodeApi;
60 63
@@ -81,16 +84,23 @@ public class AdminAuthServiceImpl implements AdminAuthService { @@ -81,16 +84,23 @@ public class AdminAuthServiceImpl implements AdminAuthService {
81 84
82 @Override 85 @Override
83 public AuthLoginRespVO login(AuthLoginReqVO reqVO) { 86 public AuthLoginRespVO login(AuthLoginReqVO reqVO) {
84 - // 使用账号密码,进行登录  
85 - AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword());  
86 -  
87 - // 如果 socialType 非空,说明需要绑定社交用户  
88 - if (reqVO.getSocialType() != null) {  
89 - socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),  
90 - reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState())); 87 + CaptchaVO captchaVO = new CaptchaVO();
  88 + captchaVO.setCaptchaVerification(reqVO.getCaptchaVerification());
  89 + ResponseModel response = captchaService.verification(captchaVO);
  90 + if(response.isSuccess()){
  91 + // 使用账号密码,进行登录
  92 + AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword());
  93 +
  94 + // 如果 socialType 非空,说明需要绑定社交用户
  95 + if (reqVO.getSocialType() != null) {
  96 + socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
  97 + reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
  98 + }
  99 + // 创建 Token 令牌,记录登录日志
  100 + return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);
  101 + }else{
  102 + throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR);
91 } 103 }
92 - // 创建 Token 令牌,记录登录日志  
93 - return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME);  
94 } 104 }
95 105
96 @Override 106 @Override