mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
系统登录改造:1、新增登录账号校验是否需要验证码;2、登录入参校验修改;3、dingding短信配置修改;4、消耗验证码顺序调整:业务执行完毕后消耗;
This commit is contained in:
+13
@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import com.cf.imes.framework.common.enums.CommonStatusEnum;
|
||||
import com.cf.imes.framework.common.enums.UserTypeEnum;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.validation.Mobile;
|
||||
import com.cf.imes.framework.operatelog.core.annotations.OperateLog;
|
||||
import com.cf.imes.framework.security.config.SecurityProperties;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
@@ -32,6 +33,7 @@ import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -39,6 +41,7 @@ import javax.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -82,6 +85,16 @@ public class AuthController {
|
||||
return success(authService.login(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/check")
|
||||
@PermitAll
|
||||
@Operation(summary = "校验账号")
|
||||
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
|
||||
@Parameter(name = "mobile", description = "手机号", required = true)
|
||||
public CommonResult<Boolean> loginCheck(
|
||||
@Param("mobile") @NotEmpty(message = "手机号不能为空") @Mobile String mobile) {
|
||||
return success(authService.loginCheck(mobile));
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
@PermitAll
|
||||
@Operation(summary = "登出系统")
|
||||
|
||||
+1
-1
@@ -76,6 +76,6 @@ public class AuthLoginReqVO {
|
||||
@AssertTrue(message = "请输入密码后登陆")
|
||||
public boolean isPasswordValid() {
|
||||
// 要么是密码登录、要么是验证码登录
|
||||
return ObjectUtil.isNotNull(password) || ObjectUtil.isNotNull(captchaVerification);
|
||||
return ObjectUtil.isNotNull(password) || ObjectUtil.isNotNull(smsCaptchaVerification);
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -34,6 +34,13 @@ public interface AdminAuthService {
|
||||
*/
|
||||
AuthLoginRespVO login(@Valid AuthLoginReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 登录校验
|
||||
* @param mobile
|
||||
* @return true需要验证码,false不需要验证码
|
||||
*/
|
||||
boolean loginCheck(String mobile);
|
||||
|
||||
/**
|
||||
* 基于 token 退出登录
|
||||
*
|
||||
|
||||
+15
@@ -150,6 +150,21 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
return createTokenAfterLoginSuccess(user.getId(), reqVO.getUsername(), LoginLogTypeEnum.LOGIN_USERNAME,organ.getLarge(), dataSourceCode, user.getOrganId(), user.getNickname());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loginCheck(String mobile) {
|
||||
// 查询账号
|
||||
AdminUserDO user = userService.getUserUniqueByUserName(mobile);
|
||||
// 校验用户是否存在
|
||||
if (user == null) {
|
||||
createLoginLog(null, mobile, LoginLogTypeEnum.LOGIN_USERNAME, LoginResultEnum.BAD_CREDENTIALS);
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.isEmpty(user.getPassword())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSmsCode(AuthSmsSendReqVO reqVO) {
|
||||
// 登录场景,验证是否存在
|
||||
|
||||
+9
-9
@@ -271,10 +271,6 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
String username = adminUserDO.getUsername();
|
||||
// 校验密码
|
||||
validatePassword(password);
|
||||
// 忘记密码消耗验证码
|
||||
smsCodeService.useSmsCode(SmsCodeUseReqDTO.builder()
|
||||
.mobile(mobile).code(reqVO.getSmsCaptchaVerification()).scene(SmsSceneEnum.USER_RESET_PASSWORD.getScene())
|
||||
.build());
|
||||
// 更新密码
|
||||
AdminUserDO updateObj = new AdminUserDO();
|
||||
updateObj.setId(userId);
|
||||
@@ -283,6 +279,10 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
|
||||
// 记录日志
|
||||
createLoginLog(userId, username, LoginLogTypeEnum.LOGIN_FORGET_PWD, LoginResultEnum.SUCCESS);
|
||||
// 消耗验证码
|
||||
smsCodeService.useSmsCode(SmsCodeUseReqDTO.builder()
|
||||
.mobile(mobile).code(reqVO.getSmsCaptchaVerification()).scene(SmsSceneEnum.USER_RESET_PASSWORD.getScene())
|
||||
.build());
|
||||
}
|
||||
|
||||
private void createLoginLog(Long userId, String username,
|
||||
@@ -655,15 +655,15 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
// 校验手机号唯一
|
||||
validateMobileUnique(id, mobile);
|
||||
|
||||
// 校验和消耗验证码
|
||||
smsCodeService.useSmsCode(SmsCodeUseReqDTO.builder()
|
||||
.mobile(reqVO.getMobile()).code(reqVO.getSmsCaptchaVerification()).scene(SmsSceneEnum.USER_UPDATE_MOBILE.getScene())
|
||||
.build());
|
||||
|
||||
// 新手机号入库 -> setUsername
|
||||
userMapper.update(new LambdaUpdateWrapper<AdminUserDO>()
|
||||
.set(AdminUserDO::getUsername, mobile)
|
||||
.eq(AdminUserDO::getId, id));
|
||||
|
||||
// 校验和消耗验证码
|
||||
smsCodeService.useSmsCode(SmsCodeUseReqDTO.builder()
|
||||
.mobile(reqVO.getMobile()).code(reqVO.getSmsCaptchaVerification()).scene(SmsSceneEnum.USER_UPDATE_MOBILE.getScene())
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -161,6 +161,7 @@ chenfeng:
|
||||
- /admin-api/system/auth/logout
|
||||
- /admin-api/system/auth/sms-code
|
||||
- /admin-api/system/user/reset-password
|
||||
- /admin-api/system/auth/check
|
||||
- /rpc-api/**
|
||||
#- /admin-api/system/**
|
||||
#- /rpc-api/system/organ/valid # 防止递归。避免调用 /rpc-api/system/organ/valid 接口时,又去触发 /rpc-api/system/organ/valid 去校验
|
||||
@@ -204,9 +205,9 @@ chenfeng:
|
||||
end-code: 9999 # 这里配置 9999 的原因是,测试方便。
|
||||
sms:
|
||||
channel: DEBUG_DING_TALK
|
||||
signature: AKhcjogF4mzWTn5G0I0sfQ==
|
||||
apiKey: Bw9mvVZZ8cLBLoPFl9yY/AI1xOUCEALEtftakrgiv9BT/dOuKUhWsXuFr9UvxRlMSRporf8Wcd7C6IFB9ukUR0IWgKTelx2vv2Lhzdnz4ac=
|
||||
apiSecret: Um956u5zFSl0tu8imFB/TOZyK7xysT5JMLY17mZIwXH+eh4BjZEmsjmFRfkcXin0A/GNhRzcUurJfm+N/S42uJZ9G9aCCIoPSjpnF9SXwt0=
|
||||
signature:
|
||||
apiKey: 28PlJanD0aJLMyMLuH6JI5oVj1/j5ZNGvZPx/zguEvJl02PdrbWe5yIV4s1RSD3CDX9obUhITNlc6glW7MNJq03N7H/v50MFgN4f8mK1oAA=
|
||||
apiSecret: O6Yk9gT3xQ9fqSKFuZa9I4bWOULCw2syH4/a1OrD2W7BAE2aQ+bSgqLXfBJT+de0GKHKgjuPNv0v+sDKkizLP22gsYIhdn/3OPSvyJF7Tng=
|
||||
encrypt:
|
||||
enable: false
|
||||
publicKey: cfimes
|
||||
|
||||
Reference in New Issue
Block a user