Skip to content

Commit

Permalink
修改密码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Jul 11, 2019
1 parent abb310b commit 1d51731
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package me.zhengjie.modules.system.domain.vo;

import lombok.Data;

/**
* 修改密码的 Vo 类
* @author Zheng Jie
* @date 2019年7月11日13:59:49
*/
@Data
public class UserPassVo {

private String oldPass;

private String newPass;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.zhengjie.domain.VerificationCode;
import me.zhengjie.modules.system.domain.User;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.vo.UserPassVo;
import me.zhengjie.modules.system.service.DeptService;
import me.zhengjie.modules.system.service.RoleService;
import me.zhengjie.modules.system.service.dto.RoleSmallDTO;
Expand Down Expand Up @@ -127,15 +128,15 @@ public ResponseEntity delete(@PathVariable Long id){
* @return
*/
@PostMapping(value = "/users/updatePass")
public ResponseEntity updatePass(@RequestBody User user){
public ResponseEntity updatePass(@RequestBody UserPassVo user){
UserDetails userDetails = SecurityUtils.getUserDetails();
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
if(!userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getOldPass()))){
throw new BadRequestException("修改失败,旧密码错误");
}
if(userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getPassword()))){
if(userDetails.getPassword().equals(EncryptUtils.encryptPassword(user.getNewPass()))){
throw new BadRequestException("新密码不能与旧密码相同");
}
userService.updatePass(userDetails.getUsername(),EncryptUtils.encryptPassword(user.getPassword()));
userService.updatePass(userDetails.getUsername(),EncryptUtils.encryptPassword(user.getNewPass()));
return new ResponseEntity(HttpStatus.OK);
}

Expand Down

0 comments on commit 1d51731

Please sign in to comment.