Skip to content

Commit 0720b10

Browse files
committed
fix(auth): 修改账号查询逻辑为邮箱查询
- 将 AdminAuthController 中的 getUserInfoByAccount 替换为 getUserInfoByEmail - 将 ClientAuthController 中的 getUserInfoByAccount 替换为 getUserInfoByEmail - 在 UserService 和 UserServiceImpl 中将方法名从 getUserInfoByAccount 改为 getUserInfoByEmail - 更新了相关调用点以使用邮箱作为查询条件 - 添加了新密码不能与旧密码相同的验证逻辑 -修复了客户端登录接口参数传递问题 Signed-off-by: LiggMax <wenzhouli06@gmail.com>
1 parent 09a631e commit 0720b10

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

common/src/main/java/com/ligg/common/service/UserService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface UserService extends IService<UserEntity> {
2424
/**
2525
* 根据账号获取用户信息
2626
*/
27-
UserEntity getUserInfoByAccount(String account);
27+
UserEntity getUserInfoByEmail(String email);
2828

2929
/**
3030
* 获取用户信息

common/src/main/java/com/ligg/common/service/impl/UserServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public void register(String account, String password) {
7979
* 根据账号获取用户信息
8080
*/
8181
@Override
82-
public UserEntity getUserInfoByAccount(String account) {
83-
return userMapper.selectOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getAccount, account));
82+
public UserEntity getUserInfoByEmail(String email) {
83+
return userMapper.selectOne(new LambdaQueryWrapper<UserEntity>()
84+
.eq(UserEntity::getEmail, email));
8485
}
8586

8687
/**

web/api-admin/src/main/java/com/ligg/apiadmin/controller/AdminAuthController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Response<String> register(@Schema(description = "账号") @NotNull String
4242
return Response.error(BusinessStates.VALIDATION_FAILED);
4343
}
4444

45-
if (userService.getUserInfoByAccount(account) != null) {
45+
if (userService.getUserInfoByEmail(account) != null) {
4646
return Response.error(BusinessStates.METHOD_NOT_ALLOWED, "该账号已被注册");
4747
}
4848
userService.register(account, password);
@@ -55,7 +55,7 @@ public Response<String> register(@Schema(description = "账号") @NotNull String
5555
@PostMapping("/login")
5656
public Response<String> login(@Schema(description = "账号") @RequestParam @NotNull String account,
5757
@Schema(description = "密码") @RequestParam @NotNull String password) {
58-
UserEntity userInfo = userService.getUserInfoByAccount(account);
58+
UserEntity userInfo = userService.getUserInfoByEmail(account);
5959
if (userInfo == null || !BCryptUtil.verify(password, userInfo.getPassword())) {
6060
return Response.error(BusinessStates.FORBIDDEN, "账号或密码错误");
6161
}

web/api-client/src/main/java/com/ligg/apiclient/controller/ClientAuthController.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Response<String> verify(@Email String email,
9191
if (!emailService.verifyEmailCode(email, emailCode)) {
9292
return Response.error(BusinessStates.METHOD_NOT_ALLOWED, "验证码错误或已过期");
9393
}
94-
return clientAccountService.updateOrInsertUserInfo(redisUserInfo,type) > 0
94+
return clientAccountService.updateOrInsertUserInfo(redisUserInfo, type) > 0
9595
? Response.success(BusinessStates.SUCCESS)
9696
: Response.error(BusinessStates.INTERNAL_SERVER_ERROR);
9797
}
@@ -100,7 +100,7 @@ public Response<String> verify(@Email String email,
100100
@PostMapping("/login")
101101
@Operation(summary = "登录", description = "提交登录信息获取token")
102102
public Response<String> login(@Validated @RequestBody LoginDto account) {
103-
UserEntity userInfo = userService.getUserInfoByAccount(account.getEmail());
103+
UserEntity userInfo = userService.getUserInfoByEmail(account.getEmail());
104104
if (userInfo == null || !BCryptUtil.verify(account.getPassword(), userInfo.getPassword())) {
105105
return Response.error(BusinessStates.FORBIDDEN, "账号或密码错误");
106106
}
@@ -127,12 +127,16 @@ public Response<String> forget(@Email(message = "参数不合法") String email,
127127
if (!captchaService.verifyCaptcha(code, uuid)) {
128128
Response.error(BusinessStates.VALIDATION_FAILED, "验证码错误");
129129
}
130-
UserEntity userInfo = userService.getUserInfoByAccount(email);
131130

131+
UserEntity userInfo = userService.getUserInfoByEmail(email);
132132
if (userInfo == null) {
133133
return Response.error(BusinessStates.NOT_FOUND, "查找的账户不存在");
134134
}
135135

136+
if (BCryptUtil.verify(password, userInfo.getPassword())) {
137+
return Response.error(BusinessStates.METHOD_NOT_ALLOWED, "新密码不能与旧密码相同");
138+
}
139+
136140
if (emailService.canSendVerificationCode(email)) {
137141
return Response.error(BusinessStates.METHOD_NOT_ALLOWED, "请勿重复发送验证码");
138142
}

0 commit comments

Comments
 (0)