Skip to content

Commit

Permalink
注销功能接口提供完善
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed Mar 31, 2022
1 parent b1291d3 commit cf01011
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public ResultMessage<Member> resetByMobile(@NotNull(message = "手机号为空")

@ApiOperation(value = "修改密码")
@ApiImplicitParams({
@ApiImplicitParam(name = "mobile", value = "手机号", required = true, paramType = "query"),
@ApiImplicitParam(name = "password", value = "是否保存登录", required = true, paramType = "query")
})
@PostMapping("/resetPassword")
Expand All @@ -152,6 +151,34 @@ public ResultMessage<Member> modifyPass(@NotNull(message = "旧密码不能为
return ResultUtil.data(memberService.modifyPass(password, newPassword));
}

@ApiOperation(value = "初始设置密码")
@ApiImplicitParams({
@ApiImplicitParam(name = "newPassword", value = "新密码", required = true, paramType = "query")
})
@PutMapping("/canInitPassword")
public ResultMessage<Object> canInitPassword() {
return ResultUtil.data(memberService.canInitPass());
}

@ApiOperation(value = "初始设置密码")
@ApiImplicitParams({
@ApiImplicitParam(name = "newPassword", value = "新密码", required = true, paramType = "query")
})
@PutMapping("/initPassword")
public ResultMessage<Object> initPassword(@NotNull(message = "密码不能为空") @RequestParam String password) {
memberService.initPass(password);
return ResultUtil.success();
}

@ApiOperation(value = "注销账号")
@ApiImplicitParams({
@ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query")
})
@PutMapping("/cancellation")
public ResultMessage<Member> cancellation(@NotNull(message = "密码不能为空") @RequestParam String password) {
memberService.cancellation(password);
return ResultUtil.success();
}

@ApiOperation(value = "刷新token")
@GetMapping("/refresh/{refreshToken}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum ResultCode {
FILE_TYPE_NOT_SUPPORT(1010, "不支持上传的文件类型!"),
PLATFORM_NOT_SUPPORTED_IM(1006, "平台未开启IM"),
STORE_NOT_SUPPORTED_IM(1007, "店铺未开启IM"),
UNINITIALIZED_PASSWORD(1008, "非初始化密码,无法进行初始化设置"),
/**
* 分类
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,11 @@ static String cacheKey(String type, String uuid) {
* @return
*/
Connect queryConnect(ConnectQueryDTO connectQueryDTO);

/**
* 根据会员id删除记录
*
* @param userId 会员id
*/
void deleteByMemberId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@ public Connect queryConnect(ConnectQueryDTO connectQueryDTO) {
return this.getOne(queryWrapper);
}

@Override
public void deleteByMemberId(String userId) {
LambdaQueryWrapper<Connect> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Connect::getUserId, userId);
this.remove(queryWrapper);
}

/**
* 会员绑定 绑定微信小程序
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public interface MemberService extends IService<Member> {

/**
* 默认密码
*/
static String DEFAULT_PASSWORD = "111111";

/**
* 获取当前登录的用户信息
*
Expand Down Expand Up @@ -92,6 +97,29 @@ public interface MemberService extends IService<Member> {
*/
Member modifyPass(String oldPassword, String newPassword);

/**
* 是否可以初始化密码
*
* @return
*/
boolean canInitPass();

/**
* 初始化密码
*
* @param password 密码
* @return 操作结果
*/
void initPass(String password);

/**
* 注销账号
*
* @param password 密码
* @return 操作结果
*/
void cancellation(String password);

/**
* 注册会员
*
Expand Down Expand Up @@ -209,7 +237,7 @@ public interface MemberService extends IService<Member> {
/**
* 获取指定会员数据
*
* @param columns 指定获取的列
* @param columns 指定获取的列
* @param memberIds 会员ids
* @return 指定会员数据
*/
Expand Down Expand Up @@ -239,6 +267,7 @@ public interface MemberService extends IService<Member> {

/**
* 获取用户VO
*
* @param id 会员id
* @return 用户VO
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public Token autoRegister(ConnectAuthUser authUser) {
Member member = new Member(username, UuidUtils.getUUID(), authUser.getAvatar(), authUser.getNickname(),
authUser.getGender() != null ? Convert.toInt(authUser.getGender().getCode()) : 0);
registerHandler(member);
member.setPassword(DEFAULT_PASSWORD);
//绑定登录方式
loginBindUser(member, authUser.getUuid(), authUser.getSource());
return memberTokenGenerate.createToken(member, false);
Expand Down Expand Up @@ -283,6 +284,67 @@ public Member modifyPass(String oldPassword, String newPassword) {
return member;
}

@Override
public boolean canInitPass() {
AuthUser tokenUser = UserContext.getCurrentUser();
if (tokenUser == null) {
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
}
Member member = this.getById(tokenUser.getId());
if (member.getPassword().equals(DEFAULT_PASSWORD)) {
return true;
}
return false;

}

@Override
public void initPass(String password) {
AuthUser tokenUser = UserContext.getCurrentUser();
if (tokenUser == null) {
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
}
Member member = this.getById(tokenUser.getId());
if (member.getPassword().equals(DEFAULT_PASSWORD)) {
//修改会员密码
LambdaUpdateWrapper<Member> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
lambdaUpdateWrapper.eq(Member::getId, member.getId());
lambdaUpdateWrapper.set(Member::getPassword, new BCryptPasswordEncoder().encode(password));
this.update(lambdaUpdateWrapper);
}
throw new ServiceException(ResultCode.UNINITIALIZED_PASSWORD);

}

@Override
public void cancellation(String password) {

AuthUser tokenUser = UserContext.getCurrentUser();
if (tokenUser == null) {
throw new ServiceException(ResultCode.USER_NOT_LOGIN);
}
Member member = this.getById(tokenUser.getId());
if (member.getPassword().equals(new BCryptPasswordEncoder().encode(password))) {
//删除联合登录
connectService.deleteByMemberId(member.getId());
//混淆用户信息
this.confusionMember(member);
}
}

/**
* 混淆之前的会员信息
*
* @param member
*/
private void confusionMember(Member member) {
member.setUsername(UuidUtils.getUUID());
member.setMobile(UuidUtils.getUUID() + member.getMobile());
member.setNickName("用户已注销");
member.setDisabled(false);
this.updateById(member);
}

@Override
public Token register(String userName, String password, String mobilePhone) {
//检测会员信息
Expand Down

0 comments on commit cf01011

Please sign in to comment.