修改指定用户密码、修改当前用户密码接口逻辑优化
This commit is contained in:
+7
-1
@@ -40,7 +40,13 @@ public class SystemContextHolder {
|
||||
}
|
||||
|
||||
public static UserDO getUser() {
|
||||
return systemContextHolder.get().getUser();
|
||||
SystemContext context = getContext();
|
||||
return (null == context) ? null : context.getUser();
|
||||
}
|
||||
|
||||
public static Integer getUserId() {
|
||||
UserDO userDO = getUser();
|
||||
return (null == userDO) ? null : userDO.getId();
|
||||
}
|
||||
|
||||
public static String getToken() {
|
||||
|
||||
+3
@@ -45,6 +45,9 @@ public enum ExceptionConstant {
|
||||
// license管理(12000)
|
||||
LICENSE_NAME_CANNOT_REPEAT(12000, "license名称不能重复"),
|
||||
LICENSE_NOT_EXIST(12001, "license数据不存在"),
|
||||
ORIGIN_PASSWORD_CHECK_FAIL(12002, "原密码验证失败"),
|
||||
LOGIN_PASSWORD_LENGTH_CHECK_FAIL(12003, "登录密码不能小于6位数"),
|
||||
LOGIN_PASSWORD_NO_CHANGE_MODIFY_FAIL(12004, "密码没有变化,修改失败"),
|
||||
// 端口池管理(13000)
|
||||
PORT_CANNOT_REPEAT(13000,"端口不能重复"),
|
||||
PORT_NOT_EXIST(13001, "该端口在端口池中不存在,不允许映射"),
|
||||
|
||||
+23
@@ -26,10 +26,15 @@ import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.db.page.Page;
|
||||
import fun.asgc.neutrino.core.db.page.PageQuery;
|
||||
import fun.asgc.neutrino.core.web.annotation.*;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.annotation.OnlyAdmin;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.*;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.dal.UserMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.service.UserService;
|
||||
import fun.asgc.neutrino.proxy.server.util.Md5Util;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.List;
|
||||
@@ -45,6 +50,8 @@ import java.util.List;
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@GetMapping("page")
|
||||
public Page<UserListRes> page(PageQuery pageQuery, UserListReq req) {
|
||||
@@ -101,6 +108,22 @@ public class UserController {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotNull(req.getId(), "id");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
|
||||
ParamCheckUtil.checkExpression(req.getLoginPassword().length() >= 6, ExceptionConstant.LOGIN_PASSWORD_LENGTH_CHECK_FAIL);
|
||||
|
||||
return userService.updatePassword(req);
|
||||
}
|
||||
|
||||
@PostMapping("current-user/update/password")
|
||||
public UserUpdatePasswordRes currentUserUpdatePassword(@RequestBody UserUpdatePasswordReq req) {
|
||||
ParamCheckUtil.checkNotNull(req, "req");
|
||||
ParamCheckUtil.checkNotEmpty(req.getOldLoginPassword(), "oldLoginPassword");
|
||||
ParamCheckUtil.checkNotEmpty(req.getLoginPassword(), "loginPassword");
|
||||
req.setId(SystemContextHolder.getUserId());
|
||||
ParamCheckUtil.checkExpression(req.getLoginPassword().length() >= 6, ExceptionConstant.LOGIN_PASSWORD_LENGTH_CHECK_FAIL);
|
||||
// 验证原密码
|
||||
Integer userId = req.getId();
|
||||
UserDO userDO = userMapper.findById(userId);
|
||||
ParamCheckUtil.checkExpression(Md5Util.encode(req.getOldLoginPassword()).equals(userDO.getLoginPassword()), ExceptionConstant.ORIGIN_PASSWORD_CHECK_FAIL);
|
||||
|
||||
return userService.updatePassword(req);
|
||||
}
|
||||
|
||||
+1
@@ -31,5 +31,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class UserUpdatePasswordReq {
|
||||
private Integer id;
|
||||
private String oldLoginPassword;
|
||||
private String loginPassword;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.core.db.page.Page;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.UserListReq;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.UserListRes;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.PortPoolDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
+7
-2
@@ -25,8 +25,6 @@ import fun.asgc.neutrino.core.annotation.Component;
|
||||
import fun.asgc.neutrino.core.annotation.Param;
|
||||
import fun.asgc.neutrino.core.aop.Intercept;
|
||||
import fun.asgc.neutrino.core.db.annotation.Delete;
|
||||
import fun.asgc.neutrino.core.db.annotation.Insert;
|
||||
import fun.asgc.neutrino.core.db.annotation.Select;
|
||||
import fun.asgc.neutrino.core.db.annotation.Update;
|
||||
import fun.asgc.neutrino.core.db.mapper.SqlMapper;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
|
||||
@@ -69,4 +67,11 @@ public interface UserTokenMapper extends SqlMapper {
|
||||
|
||||
@Update("update user_token set expiration_time = :expirationTime where token = :token")
|
||||
void updateTokenExpirationTime(@Param("token") String token, @Param("expirationTime") Date expirationTime);
|
||||
|
||||
/**
|
||||
* 根据userId删除token
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from user_token where user_id = ?")
|
||||
void deleteByUserId(Integer userId);
|
||||
}
|
||||
|
||||
+11
-2
@@ -27,10 +27,10 @@ import fun.asgc.neutrino.core.annotation.NonIntercept;
|
||||
import fun.asgc.neutrino.core.db.page.Page;
|
||||
import fun.asgc.neutrino.core.db.page.PageQuery;
|
||||
import fun.asgc.neutrino.core.util.DateUtil;
|
||||
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.ServiceException;
|
||||
import fun.asgc.neutrino.proxy.server.base.rest.SystemContextHolder;
|
||||
import fun.asgc.neutrino.proxy.server.constant.EnableStatusEnum;
|
||||
import fun.asgc.neutrino.proxy.server.constant.ExceptionConstant;
|
||||
import fun.asgc.neutrino.proxy.server.controller.req.*;
|
||||
import fun.asgc.neutrino.proxy.server.controller.res.*;
|
||||
import fun.asgc.neutrino.proxy.server.dal.UserLoginRecordMapper;
|
||||
@@ -40,6 +40,7 @@ import fun.asgc.neutrino.proxy.server.dal.entity.UserDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserLoginRecordDO;
|
||||
import fun.asgc.neutrino.proxy.server.dal.entity.UserTokenDO;
|
||||
import fun.asgc.neutrino.proxy.server.util.Md5Util;
|
||||
import fun.asgc.neutrino.proxy.server.util.ParamCheckUtil;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@@ -192,8 +193,16 @@ public class UserService {
|
||||
}
|
||||
|
||||
public UserUpdatePasswordRes updatePassword(UserUpdatePasswordReq req) {
|
||||
UserDO userDO = userMapper.findById(req.getId());
|
||||
// 更新密码
|
||||
String loginPassword = Md5Util.encode(req.getLoginPassword());
|
||||
ParamCheckUtil.checkExpression(!userDO.getLoginPassword().equals(loginPassword), ExceptionConstant.LOGIN_PASSWORD_NO_CHANGE_MODIFY_FAIL);
|
||||
|
||||
userMapper.updateLoginPassword(req.getId(), loginPassword, new Date());
|
||||
|
||||
// 删除该用户所有token
|
||||
userTokenMapper.deleteByUserId(req.getId());
|
||||
|
||||
return new UserUpdatePasswordRes();
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -1,7 +1,7 @@
|
||||
- 测试及优化代理稳定性
|
||||
- 完成剩余的调度管理日志功能
|
||||
- 增加日志管理(登录日志、客户端连接日志、调度执行日志)
|
||||
- 增加简单的流量统计
|
||||
- 基于用户粒度的上下行流量累计
|
||||
- 完善补充代码文档
|
||||
- 优化底层框架
|
||||
# BUG
|
||||
- neutrino-proxy-admin 打包后启动,token失效不会跳回登录页面
|
||||
|
||||
# 优化
|
||||
- 调度管理,增加查看按钮,解决异常情况下,列表展示堆栈异常信息不全,不方便查看的问题
|
||||
- 用户列表增加修改密码入口,管理员可以修改指定用户密码,无需验证原密码(仅管理员操作
|
||||
- 增加当前登录用户修改自己密码的功能,需要验证原密码
|
||||
Reference in New Issue
Block a user