fix: 修正

This commit is contained in:
wangyu 2021-01-11 23:49:44 +08:00
parent 13e1180230
commit a994b7d56b
2 changed files with 13 additions and 3 deletions

View File

@ -9,13 +9,19 @@ import com.flyfish.framework.domain.po.User;
import com.flyfish.framework.service.UserService;
import com.flyfish.framework.utils.Assert;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import javax.annotation.Resource;
@RestController
@RequestMapping("/users")
public class UserController extends BaseController<User, UserQo> {
@Resource
private PasswordEncoder passwordEncoder;
/**
* 修改密码逻辑
*
@ -26,13 +32,13 @@ public class UserController extends BaseController<User, UserQo> {
@PutMapping("/passwords")
public Result<Void> changePassword(@RequestBody UserPasswordDto passwordDto, @CurrentUser User user) {
// 检查原密码
Assert.isTrue(user.getPassword().equals(passwordDto.getOldPassword()), "原密码不正确!");
Assert.isTrue(!user.getPassword().equals(passwordDto.getPassword()), "新密码和旧密码一致,输入个新的吧!");
Assert.isTrue(passwordEncoder.matches(passwordDto.getOldPassword(), user.getPassword()), "原密码不正确!");
Assert.isTrue(!passwordEncoder.matches(passwordDto.getPassword(), user.getPassword()), "新密码和旧密码一致,输入个新的吧!");
userContext.setUser(user);
// 更新密码
User updating = new User();
updating.setId(user.getId());
updating.setPassword(passwordDto.getPassword());
updating.setPassword(passwordEncoder.encode(passwordDto.getPassword()));
service.updateSelectiveById(updating);
return Result.ok();
}

View File

@ -3,6 +3,8 @@ package com.flyfish.framework.domain;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotBlank;
/**
* 修改密码dto
* @author wangyu
@ -11,7 +13,9 @@ import lombok.Setter;
@Setter
public class UserPasswordDto {
@NotBlank(message = "旧密码不可为空!")
private String oldPassword;
@NotBlank(message = "新密码不可为空!")
private String password;
}