后台新增重置用户登录密码功能
This commit is contained in:
parent
89828d0924
commit
c3f2e428ac
@ -10,6 +10,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd;
|
||||
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO;
|
||||
@ -124,4 +125,10 @@ public interface AppUserAccountClientApi {
|
||||
@GetMapping(value = "/lastApprovalUserAccountStatusLog")
|
||||
ResultResponse<List<ApprovalUserAccountStatusLogDTO>> lastApprovalUserAccountStatusLog(
|
||||
@RequestParam("beApprovalUser") Long beApprovalUser, @RequestParam("size") Integer size);
|
||||
|
||||
/**
|
||||
* 重置密码.
|
||||
*/
|
||||
@PostMapping(value = "/resetPassword")
|
||||
ResultResponse<Void> resetPassword(@RequestBody @Validated ResetPasswordCmd cmd);
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.red.circle.other.inner.model.cmd.user.account;
|
||||
|
||||
import com.red.circle.common.business.dto.cmd.AppExtCommand;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 重置密码命令
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ResetPasswordCmd extends AppExtCommand {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
@NotNull(message = "用户ID不能为空")
|
||||
private Long userId;
|
||||
}
|
||||
@ -7,6 +7,8 @@ import com.red.circle.console.app.service.app.user.UserAuthTypeService;
|
||||
import com.red.circle.console.infra.annotations.OpsOperationReqLog;
|
||||
import com.red.circle.framework.core.security.UserCredential;
|
||||
import com.red.circle.framework.web.controller.BaseController;
|
||||
import com.red.circle.other.inner.endpoint.user.user.AppUserAccountClient;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd;
|
||||
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.UserMobileUpdateCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -34,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class UserAuthTypeRestController extends BaseController {
|
||||
|
||||
private final UserAuthTypeService userAuthTypeService;
|
||||
private final AppUserAccountClient appUserAccountClient;
|
||||
|
||||
/**
|
||||
* 获取注册信息.
|
||||
@ -97,6 +100,21 @@ public class UserAuthTypeRestController extends BaseController {
|
||||
userAuthTypeService.initUserAccountLogin(userId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重置用户密码为默认密码
|
||||
*
|
||||
* @eo.name 重置用户密码
|
||||
* @eo.url /account/resetPassword
|
||||
* @eo.method post
|
||||
* @eo.request-type json
|
||||
*/
|
||||
@OpsOperationReqLog("重置用户密码")
|
||||
@PostMapping("/account/resetPassword")
|
||||
public void resetPassword(@RequestBody @Validated ResetPasswordCmd cmd) {
|
||||
appUserAccountClient.resetPassword(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户账号密码登录信息.
|
||||
*/
|
||||
|
||||
@ -8,11 +8,7 @@ import com.red.circle.other.infra.annotation.CreateAccount;
|
||||
import com.red.circle.other.inner.endpoint.user.user.api.AppUserAccountClientApi;
|
||||
import com.red.circle.other.inner.model.cmd.user.ApprovalUserAccountStatusLogCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.UserChannelCredentialCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.*;
|
||||
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.UserAccountDTO;
|
||||
@ -174,4 +170,11 @@ public class AppUserAccountClientEndpoint implements AppUserAccountClientApi {
|
||||
return ResultResponse.success(
|
||||
userAccountClientService.lastApprovalUserAccountStatusLog(beApprovalUser, size));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultResponse<Void> resetPassword(ResetPasswordCmd cmd) {
|
||||
userAccountClientService.resetPassword(cmd);
|
||||
return ResultResponse.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd;
|
||||
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO;
|
||||
@ -96,4 +97,9 @@ public interface UserAccountClientService {
|
||||
PageResult<ApprovalUserAccountStatusLogDTO> pgeApprovalUserAccountStatusLog(UserAccountStatusLogQryCmd cmd);
|
||||
|
||||
List<ApprovalUserAccountStatusLogDTO> lastApprovalUserAccountStatusLog(Long beApprovalUser, Integer size);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
void resetPassword(ResetPasswordCmd cmd);
|
||||
}
|
||||
|
||||
@ -31,6 +31,7 @@ import com.red.circle.other.infra.database.rds.entity.user.user.ApprovalUserAcco
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.AuthType;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.BaseInfo;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.LogoutRecord;
|
||||
import com.red.circle.other.infra.database.rds.entity.user.user.PasswordLog;
|
||||
import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.device.ArchiveDeviceService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.device.LatestMobileDeviceService;
|
||||
@ -40,6 +41,7 @@ import com.red.circle.other.infra.database.rds.service.user.user.AuthTypeService
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.BaseInfoService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.LogoutRecordService;
|
||||
import com.red.circle.other.infra.database.rds.service.user.user.MobileAuthService;
|
||||
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 com.red.circle.other.inner.model.cmd.user.UserChannelCredentialCmd;
|
||||
@ -47,6 +49,7 @@ import com.red.circle.other.inner.model.cmd.user.account.AccountLoginCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.CreateAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.MobileCredentialCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.ResetPasswordCmd;
|
||||
import com.red.circle.other.inner.model.cmd.user.account.UnblockAccountCmd;
|
||||
import com.red.circle.other.inner.model.dto.user.UserAuthTypeDTO;
|
||||
import com.red.circle.other.inner.model.dto.user.account.MobileAuthDTO;
|
||||
@ -98,6 +101,7 @@ public class UserAccountClientServiceImpl implements UserAccountClientService {
|
||||
private final UserAccountAuthCacheService accountAuthCacheService;
|
||||
private final UserAccountAuthCacheService userAccountAuthCacheService;
|
||||
private final ApprovalUserAccountStatusLogService approvalUserAccountStatusLogService;
|
||||
private final PasswordLogService passwordLogService;
|
||||
|
||||
@Override
|
||||
public UserAccountDTO create(CreateAccountCmd cmd) {
|
||||
@ -431,4 +435,52 @@ public class UserAccountClientServiceImpl implements UserAccountClientService {
|
||||
private String requestUserSign(Long userId) {
|
||||
return ResponseAssert.requiredSuccess(imAccountClient.createUserSig(userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPassword(ResetPasswordCmd cmd) {
|
||||
Long userId = cmd.getUserId();
|
||||
String newPassword = "123456";
|
||||
|
||||
// 验证用户是否存在
|
||||
UserProfile userProfile = userProfileGateway.getByUserId(userId);
|
||||
ResponseAssert.notNull(UserErrorCode.USER_INFO_NOT_FOUND, userProfile);
|
||||
|
||||
// 获取旧的账号认证信息
|
||||
AccountAuth oldAccountAuth = accountAuthService.getByUserId(userId);
|
||||
|
||||
// 如果存在旧密码,删除旧的认证信息
|
||||
if (Objects.nonNull(oldAccountAuth)) {
|
||||
accountAuthService.deleteById(oldAccountAuth.getId());
|
||||
authTypeService.deleteAuthType(userId, AuthTypeEnum.ACCOUNT.name());
|
||||
}
|
||||
|
||||
// 保存新密码
|
||||
accountAuthService.saveAccountAuth(new AccountAuth()
|
||||
.setUserId(userId)
|
||||
.setPwd(newPassword)
|
||||
.setDel(Boolean.FALSE));
|
||||
|
||||
// 保存认证类型
|
||||
AuthType authType = new AuthType();
|
||||
authType.setUserId(userId);
|
||||
authType.setType(AuthTypeEnum.ACCOUNT.name());
|
||||
authType.setOpenId(String.valueOf(userId));
|
||||
authType.setDel(Boolean.FALSE);
|
||||
authTypeService.save(authType);
|
||||
|
||||
// 记录密码修改日志
|
||||
passwordLogService.save(PasswordLog.builder()
|
||||
.businessType("ACCOUNT_PASSWORD")
|
||||
.operateType("RESET_PASSWORD")
|
||||
.userId(userId)
|
||||
.sysOrigin(userProfile.getOriginSys())
|
||||
.pwd(newPassword)
|
||||
.imei(cmd.getReqImei())
|
||||
.build());
|
||||
|
||||
// 清除密码登录缓存
|
||||
accountAuthCacheService.deleteByUserId(userId);
|
||||
|
||||
log.info("重置用户密码成功, userId: {}, newPassword: {}", userId, newPassword);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user