微调
This commit is contained in:
@@ -22,7 +22,9 @@ public enum UserResponseEnum {
|
||||
COMPONENT_NOT_BLANK("A010011", "组件地址不能为空"),
|
||||
FUNCTION_PATH_FORMAT_ERROR("A010012", "路由地址格式错误"),
|
||||
SUPER_ADMIN_REPEAT("A010013","超级管理员已存在,请勿重复添加" ),
|
||||
RSA_DECRYT_ERROR("A010014","RSA解密失败" );
|
||||
RSA_DECRYT_ERROR("A010014","RSA解密失败" ),
|
||||
PASSWORD_SAME("A010015", "新密码不能与旧密码相同"),
|
||||
OLD_PASSWORD_ERROR("A010016", "旧密码错误");
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
@@ -4,13 +4,10 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.constant.SecurityConstants;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.JwtUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.user.pojo.constant.UserValidMessage;
|
||||
import com.njcn.gather.user.user.pojo.param.SysUserParam;
|
||||
import com.njcn.gather.user.user.pojo.po.SysUser;
|
||||
import com.njcn.gather.user.user.service.ISysUserService;
|
||||
@@ -22,11 +19,9 @@ import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -120,21 +115,12 @@ public class SysUserController extends BaseController {
|
||||
public HttpResult<Object> updatePassword(@RequestBody @Validated SysUserParam.SysUserUpdatePasswordParam param) {
|
||||
String methodDescribe = getMethodDescribe("updatePassword");
|
||||
LogUtil.njcnDebug(log, "{},用户id:{},用户旧密码:{},新密码:{}", methodDescribe, param.getId(), param.getOldPassword(), param.getNewPassword());
|
||||
if (param.getOldPassword().equals(param.getNewPassword())) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "新密码不能与旧密码相同", methodDescribe);
|
||||
}
|
||||
boolean result = sysUserService.oldPwdConfirm(param.getId(), param.getOldPassword());
|
||||
boolean result = sysUserService.updatePassword(param);
|
||||
if (!result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "原密码错误", methodDescribe);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
} else {
|
||||
result = sysUserService.updatePassword(param.getId(), param.getNewPassword());
|
||||
if (!result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, "修改密码失败", methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -82,22 +82,11 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
*/
|
||||
boolean updateUser(SysUserParam.SysUserUpdateParam updateUserParam);
|
||||
|
||||
/**
|
||||
* 原密码确认
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param oldPassword 原密码
|
||||
* @return 结果,true表示确认成功,false表示确认失败
|
||||
*/
|
||||
boolean oldPwdConfirm(String userId, String oldPassword);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param userId
|
||||
* @param newPassword
|
||||
* @return 结果,true表示修改成功,false表示修改失败
|
||||
*/
|
||||
boolean updatePassword(String userId, String newPassword);
|
||||
boolean updatePassword(SysUserParam.SysUserUpdatePasswordParam param);
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
|
||||
@@ -144,28 +144,22 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
return this.updateById(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean oldPwdConfirm(String userId, String oldPassword) {
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getId, userId).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
if (sm4.encryptData_ECB(oldPassword).equals(user.getPassword())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updatePassword(String userId, String newPassword) {
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getId, userId).one();
|
||||
public boolean updatePassword(SysUserParam.SysUserUpdatePasswordParam param) {
|
||||
if (param.getOldPassword().equals(param.getNewPassword())) {
|
||||
throw new BusinessException(UserResponseEnum.PASSWORD_SAME);
|
||||
}
|
||||
SysUser user = lambdaQuery().ne(SysUser::getState, UserConst.STATE_DELETE).eq(SysUser::getId, param.getId()).one();
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
String secretkey = Sm4Utils.globalSecretKey;
|
||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
||||
user.setPassword(sm4.encryptData_ECB(newPassword));
|
||||
return this.updateById(user);
|
||||
if (sm4.encryptData_ECB(param.getOldPassword()).equals(user.getPassword())) {
|
||||
user.setPassword(sm4.encryptData_ECB(param.getNewPassword()));
|
||||
return this.updateById(user);
|
||||
}else {
|
||||
throw new BusinessException(UserResponseEnum.OLD_PASSWORD_ERROR);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user