fix: 修复强制重置密码流程与表单状态
- 修正强制改密跳转及免旧密码的服务端校验 - 统一双端表单错误布局与更新按钮加载状态 - 补充认证服务和强制改密路由测试
This commit is contained in:
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import tech.easyflow.auth.entity.EncryptedCredentialDTO;
|
||||
import tech.easyflow.auth.service.AuthCredentialKeyService;
|
||||
import tech.easyflow.auth.service.AuthService;
|
||||
import tech.easyflow.common.constant.enums.EnumAccountType;
|
||||
import tech.easyflow.common.constant.enums.EnumDataStatus;
|
||||
import tech.easyflow.common.domain.Result;
|
||||
@@ -30,6 +31,7 @@ import tech.easyflow.system.entity.vo.SysAccountImportResultVo;
|
||||
import tech.easyflow.system.service.SysAccountService;
|
||||
import tech.easyflow.system.util.SysPasswordPolicy;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URLEncoder;
|
||||
@@ -48,6 +50,8 @@ import java.util.Map;
|
||||
@RequestMapping("/api/v1/sysAccount")
|
||||
public class SysAccountController extends BaseCurdController<SysAccountService, SysAccount> {
|
||||
private final AuthCredentialKeyService credentialKeyService;
|
||||
@Resource
|
||||
private AuthService authService;
|
||||
|
||||
public SysAccountController(SysAccountService service, AuthCredentialKeyService credentialKeyService) {
|
||||
super(service);
|
||||
@@ -150,7 +154,8 @@ public class SysAccountController extends BaseCurdController<SysAccountService,
|
||||
/**
|
||||
* 修改密码,用于修改用户自己的密码
|
||||
*
|
||||
* @param encryptedCredential 加密后的旧密码、新密码与确认密码
|
||||
* @param encryptedCredential 加密后的当前密码、新密码与确认密码
|
||||
* @return 密码修改结果
|
||||
*/
|
||||
@PostMapping("/updatePassword")
|
||||
public Result<Void> updatePassword(@JsonBody EncryptedCredentialDTO encryptedCredential) {
|
||||
@@ -159,25 +164,13 @@ public class SysAccountController extends BaseCurdController<SysAccountService,
|
||||
String newPassword = payload.getString("newPassword");
|
||||
String confirmPassword = payload.getString("confirmPassword");
|
||||
BigInteger loginAccountId = SaTokenUtil.getLoginAccount().getId();
|
||||
SysAccount record = service.getById(loginAccountId);
|
||||
if (record == null) {
|
||||
return Result.fail("修改失败");
|
||||
}
|
||||
String pwdDb = record.getPassword();
|
||||
if (!BCrypt.checkpw(password, pwdDb)) {
|
||||
return Result.fail(1, "密码不正确");
|
||||
}
|
||||
if (!newPassword.equals(confirmPassword)) {
|
||||
return Result.fail(2, "两次密码不一致");
|
||||
}
|
||||
SysPasswordPolicy.validateStrongPassword(newPassword);
|
||||
SysAccount update = new SysAccount();
|
||||
update.setId(loginAccountId);
|
||||
update.setPassword(BCrypt.hashpw(newPassword));
|
||||
update.setPasswordResetRequired(false);
|
||||
update.setModified(new Date());
|
||||
update.setModifiedBy(loginAccountId);
|
||||
service.updateById(update);
|
||||
authService.updateOwnPassword(
|
||||
loginAccountId,
|
||||
password,
|
||||
newPassword,
|
||||
confirmPassword,
|
||||
StpUtil.getLoginDevice()
|
||||
);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user