feat(user): 添加更新用户名功能并优化安全配置
- 在 ErrorCode 中新增 USER_UPDATE_USERNAME_FAILED 错误码 - JwtAuthenticationTokenFilter 中增加当前用户名属性设置 - RestAuthenticationEntryPoint 返回状态码改为 403 并更新错误信息 - 新增 UpdateUsernameRequest DTO 用于接收用户名更新请求 - UserController 添加 updateUsername 接口支持修改用户名 - UserInfoService 和其实现类中增加 updateUsername 方法逻辑 - 引入 tokenHead 配置项以支持 JWT 相关操作
This commit is contained in:
@@ -71,5 +71,23 @@ public class UserInfoServiceImpl implements UserInfoService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUsername(String username, String newUsername) {
|
||||
if (newUsername == null || newUsername.isEmpty()){
|
||||
throw new BizException(ErrorCode.USER_UPDATE_USERNAME_FAILED);
|
||||
}
|
||||
User user = userMapper.selectByUsername(username);
|
||||
if (user == null) {
|
||||
throw new BizException(ErrorCode.USER_NOT_EXISTS);
|
||||
}
|
||||
user.setUsername(newUsername);
|
||||
int i = userMapper.updateById(user);
|
||||
log.info("更新用户名结果: {}", i);
|
||||
if (i == 0) {
|
||||
throw new BizException(ErrorCode.USER_UPDATE_USERNAME_FAILED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user