diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java index 9de289f6..8866cc05 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/asserts/user/UserErrorCode.java @@ -218,6 +218,9 @@ public enum UserErrorCode implements IResponseErrorCode { //不在当前团队 ,NOT_IN_TEAM(4073, "Not in team") + // 密码不正确 + ,PASSWORD_NOT_MATCH(4074, "password is incorrect") + ; diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/account/AppUserAccountRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/account/AppUserAccountRestController.java index e10d9041..1e9901ca 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/account/AppUserAccountRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/account/AppUserAccountRestController.java @@ -45,12 +45,7 @@ public class AppUserAccountRestController extends BaseController { /** - * 修改账号密码(账号). - * - * @eo.name 修改账号密码(账号). - * @eo.url /account-pwd-reset - * @eo.method post - * @eo.request-type json + * 删除账号密码 */ @PostMapping(value = "/account-pwd-reset", consumes = MediaType.APPLICATION_JSON_VALUE) public void accountPwdUpdate(@RequestBody @Validated AccountPwdResetCmd cmd) { diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserAuthTypeRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserAuthTypeRestController.java index 25a093fc..6b76d436 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserAuthTypeRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/user/UserAuthTypeRestController.java @@ -67,12 +67,7 @@ public class UserAuthTypeRestController extends BaseController { } /** - * 账号绑定认证关系. - * - * @eo.name 账号绑定认证关系. - * @eo.url /account-bind - * @eo.method post - * @eo.request-type json + * 设置账号密码. */ @PostMapping("/account-bind") public void accountBindUserAuthType(@RequestBody @Validated AccountBindUserAuthTypeCmd cmd) { diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/AccountBindUserAuthTypeCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/AccountBindUserAuthTypeCmdExe.java index 43077533..5dd170d1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/AccountBindUserAuthTypeCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/AccountBindUserAuthTypeCmdExe.java @@ -1,16 +1,24 @@ package com.red.circle.other.app.command.user; +import com.red.circle.component.redis.service.RedisService; import com.red.circle.framework.core.asserts.ResponseAssert; +import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.other.app.dto.cmd.user.user.AccountBindUserAuthTypeCmd; import com.red.circle.other.infra.database.rds.entity.user.user.AccountAuth; import com.red.circle.other.infra.database.rds.entity.user.user.AuthType; +import com.red.circle.other.infra.database.rds.entity.user.user.PasswordLog; import com.red.circle.other.infra.database.rds.service.user.user.AccountAuthService; import com.red.circle.other.infra.database.rds.service.user.user.AuthTypeService; +import com.red.circle.other.infra.database.rds.service.user.user.PasswordLogService; import com.red.circle.other.inner.asserts.user.UserErrorCode; import com.red.circle.other.inner.enums.user.AuthTypeEnum; + +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; + +import com.red.circle.tool.core.collection.CollectionUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -25,31 +33,33 @@ public class AccountBindUserAuthTypeCmdExe { private final AuthTypeService authTypeService; private final AccountAuthService accountAuthService; + private final PasswordLogService passwordLogService; public void execute(AccountBindUserAuthTypeCmd cmd) { - - AuthType authType = authTypeService.getAuthInfo( - AuthTypeEnum.ACCOUNT.name(), - cmd.requiredReqUserIdStr() - ); - - // 4032 已被绑定 - ResponseAssert.isNull(UserErrorCode.ALREADY_USED, authType); - - AccountAuth accountAuth = accountAuthService.getByUserId(cmd.requiredReqUserId()); - - ResponseAssert.isNull(UserErrorCode.ALREADY_USED, accountAuth); //4061 密码不符合规则 - ResponseAssert.isTrue(UserErrorCode.ACCOUNT_PASSWORD_NOT_COMPLY_WITH_RULES, - validatePassword(cmd.getPwd())); + ResponseAssert.isTrue(UserErrorCode.ACCOUNT_PASSWORD_NOT_COMPLY_WITH_RULES, validatePassword(cmd.getPwd())); + + AccountAuth accountAuth = accountAuthService.getByPassword(cmd.getOldPwd(), cmd.getReqUserId()); + ResponseAssert.notNull(UserErrorCode.PASSWORD_NOT_MATCH, accountAuth); + + ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, accountAuthService.deleteById(accountAuth.getId())); + authTypeService.deleteAuthType(cmd.getReqUserId(), AuthTypeEnum.ACCOUNT.name()); accountAuthService.saveAccountAuth(new AccountAuth() - .setUserId(cmd.requiredReqUserId()) - .setPwd(cmd.getPwd()) - .setDel(Boolean.FALSE) - ); + .setUserId(cmd.requiredReqUserId()) + .setPwd(cmd.getPwd()) + .setDel(Boolean.FALSE)); authTypeService.save(toAuthType(cmd.requiredReqUserId(), cmd)); + + passwordLogService.save(PasswordLog.builder() + .businessType("ACCOUNT_PASSWORD") + .operateType("UPDATE_PASSWORD") + .userId(cmd.getReqUserId()) + .sysOrigin(cmd.requireReqSysOrigin()) + .pwd(cmd.getPwd()) + .imei(cmd.getReqImei()) + .build()); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/AccountBindUserAuthTypeCmd.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/AccountBindUserAuthTypeCmd.java index be5a42e8..6b6c412b 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/AccountBindUserAuthTypeCmd.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/cmd/user/user/AccountBindUserAuthTypeCmd.java @@ -23,4 +23,9 @@ public class AccountBindUserAuthTypeCmd extends AppExtCommand { @NotBlank(message = "pwd required.") private String pwd; + /** + * 旧密码 + */ + private String oldPwd; + }