feat(user): 添加用户修改密码功能
- 在前端 HomePage 组件中添加修改密码对话框 - 在 API 中添加 updatePassword 接口 - 在后端 UserController 中添加密码更新接口 - 在 UserService 中添加 updatePassword 方法 - 实现密码更新逻辑,包括旧密码验证和新密码加密
This commit is contained in:
@@ -3,6 +3,8 @@ package com.test.bijihoudaun.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.test.bijihoudaun.entity.User;
|
||||
|
||||
import com.test.bijihoudaun.bo.UpdatePasswordBo;
|
||||
|
||||
public interface UserService extends IService<User> {
|
||||
/**
|
||||
* 用户注册
|
||||
@@ -33,4 +35,11 @@ public interface UserService extends IService<User> {
|
||||
* @return Boolean
|
||||
*/
|
||||
Boolean isTokenExpired(Long id,String token);
|
||||
|
||||
/**
|
||||
* 更新用户密码
|
||||
* @param userId 用户ID
|
||||
* @param updatePasswordBo 包含新旧密码的对象
|
||||
*/
|
||||
void updatePassword(Long userId, UpdatePasswordBo updatePasswordBo);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.test.bijihoudaun.service.impl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.test.bijihoudaun.bo.UpdatePasswordBo;
|
||||
import com.test.bijihoudaun.common.exception.BusinessException;
|
||||
import com.test.bijihoudaun.common.exception.RegistrationException;
|
||||
import com.test.bijihoudaun.entity.User;
|
||||
import com.test.bijihoudaun.mapper.UserMapper;
|
||||
@@ -83,4 +85,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
// 修改过期检查逻辑
|
||||
return user != null && new Date().before(user.getTokenEnddata());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePassword(Long userId, UpdatePasswordBo updatePasswordBo) {
|
||||
User user = getById(userId);
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
if (!PasswordUtils.verify(updatePasswordBo.getOldPassword(), user.getPassword())) {
|
||||
throw new BusinessException("旧密码不正确");
|
||||
}
|
||||
String newPassword = PasswordUtils.encrypt(updatePasswordBo.getNewPassword());
|
||||
user.setPassword(newPassword);
|
||||
updateById(user);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user