feat(user): 添加更新用户名功能并优化安全配置

- 在 ErrorCode 中新增 USER_UPDATE_USERNAME_FAILED 错误码
- JwtAuthenticationTokenFilter 中增加当前用户名属性设置
- RestAuthenticationEntryPoint 返回状态码改为 403 并更新错误信息
- 新增 UpdateUsernameRequest DTO 用于接收用户名更新请求
- UserController 添加 updateUsername 接口支持修改用户名
- UserInfoService 和其实现类中增加 updateUsername 方法逻辑
- 引入 tokenHead 配置项以支持 JWT 相关操作
This commit is contained in:
Chaos
2025-11-18 22:32:51 +08:00
parent 7e754b19d4
commit 7dc0d26d9b
7 changed files with 56 additions and 8 deletions

View File

@@ -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);
}
}
}