refactor: 支持首次登录重置密码
This commit is contained in:
@@ -20,7 +20,7 @@ import org.agt.module.system.controller.admin.auth.vo.AuthLoginReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthLoginRespVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthPermissionInfoRespVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthRegisterReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthResetPasswordReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthResetPasswordByNameReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthSmsLoginReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthSmsSendReqVO;
|
||||
import org.agt.module.system.controller.admin.auth.vo.AuthSocialLoginReqVO;
|
||||
@@ -164,8 +164,8 @@ public class AuthController {
|
||||
@PostMapping("/reset-password")
|
||||
@PermitAll
|
||||
@Operation(summary = "重置密码")
|
||||
public CommonResult<Boolean> resetPassword(@RequestBody @Valid AuthResetPasswordReqVO reqVO) {
|
||||
authService.resetPassword(reqVO);
|
||||
public CommonResult<Boolean> resetPassword(@RequestBody @Valid AuthResetPasswordByNameReqVO reqVO) {
|
||||
authService.resetPasswordByName(reqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.agt.module.system.controller.admin.auth.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
@Schema(description = "管理后台 - 短信重置账号密码 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class AuthResetPasswordByNameReqVO {
|
||||
|
||||
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1234")
|
||||
@NotEmpty(message = "密码不能为空")
|
||||
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "用户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "test")
|
||||
@NotEmpty(message = "用户名称不能为空")
|
||||
private String username;
|
||||
}
|
||||
@@ -84,4 +84,11 @@ public interface AdminAuthService {
|
||||
*/
|
||||
void resetPassword(AuthResetPasswordReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 通过用户名称重置密码
|
||||
*
|
||||
* @param reqVO 密码信息
|
||||
*/
|
||||
void resetPasswordByName(AuthResetPasswordByNameReqVO reqVO);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package org.agt.module.system.service.auth;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.anji.captcha.model.common.ResponseModel;
|
||||
import com.anji.captcha.model.vo.CaptchaVO;
|
||||
import com.anji.captcha.service.CaptchaService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.agt.framework.common.enums.CommonStatusEnum;
|
||||
import org.agt.framework.common.enums.UserTypeEnum;
|
||||
import org.agt.framework.common.util.monitor.TracerUtils;
|
||||
@@ -24,14 +32,6 @@ import org.agt.module.system.service.member.MemberService;
|
||||
import org.agt.module.system.service.oauth2.OAuth2TokenService;
|
||||
import org.agt.module.system.service.social.SocialUserService;
|
||||
import org.agt.module.system.service.user.AdminUserService;
|
||||
import com.anji.captcha.model.common.ResponseModel;
|
||||
import com.anji.captcha.model.vo.CaptchaVO;
|
||||
import com.anji.captcha.service.CaptchaService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -104,6 +104,11 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
// 使用账号密码,进行登录
|
||||
AdminUserDO user = authenticate(reqVO.getUsername(), reqVO.getPassword());
|
||||
|
||||
// 首次登录不返回token
|
||||
if (user.getLoginDate() == null) {
|
||||
return new AuthLoginRespVO();
|
||||
}
|
||||
|
||||
// 如果 socialType 非空,说明需要绑定社交用户
|
||||
if (reqVO.getSocialType() != null) {
|
||||
socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
|
||||
@@ -300,4 +305,15 @@ public class AdminAuthServiceImpl implements AdminAuthService {
|
||||
|
||||
userService.updateUserPassword(userByMobile.getId(), reqVO.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void resetPasswordByName(AuthResetPasswordByNameReqVO reqVO) {
|
||||
AdminUserDO user = userService.getUserByUsername(reqVO.getUsername());
|
||||
if (user == null) {
|
||||
throw exception(USER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
userService.updateUserPassword(user.getId(), reqVO.getPassword());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,6 +217,7 @@ public class AdminUserServiceImpl implements AdminUserService {
|
||||
AdminUserDO updateObj = new AdminUserDO();
|
||||
updateObj.setId(id);
|
||||
updateObj.setPassword(encodePassword(password)); // 加密密码
|
||||
updateObj.setLoginDate(LocalDateTime.now());
|
||||
userMapper.updateById(updateObj);
|
||||
|
||||
// 3. 记录操作日志上下文
|
||||
|
||||
Reference in New Issue
Block a user