Commit ae9c7eac authored by “xuhd”'s avatar “xuhd”

密码修改

parent 5a6aa1e7
......@@ -20,6 +20,7 @@ import com.hungraim.ltc.util.Result;
import com.hungraim.ltc.util.ResultCode;
import com.hungraim.ltc.util.TokenParsingUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
......@@ -295,6 +296,43 @@ public class UserController {
return Result.success("更新成功");
}
@PostMapping("/updatePassword")
public Result updatePassword(String oldPassword,String newPassword,@RequestHeader("Authorization") String token){
log.info("oldPassword:"+oldPassword+",newPassword:"+newPassword);
if(StringUtils.isBlank(newPassword) || StringUtils.isBlank(oldPassword)){
Result.failed(ResultCode.REQUEST_PARAM_ERROR);
}
//校验旧密码是否匹配
Integer userId = TokenParsingUtil.TokenParsing(token, "userId");
if(userId == null){
return Result.failed("未获取到用户信息!");
}
SystemUser userinfo = userInfoService.getById(userId);
if(userinfo == null){
return Result.failed("未获取到用户信息!");
}
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
String userinfoPassword = userinfo.getPassword();
if(!bCryptPasswordEncoder.matches(oldPassword, userinfoPassword)){
return Result.failed("旧密码不匹配!");
}
if (CheckStrength.checkPasswordStrength(newPassword) < 4) {
return Result.failed("密码太简单,请设置复杂密码!");
}
SystemUser user = new SystemUser();
user.setPassword(new BCryptPasswordEncoder().encode(newPassword));
user.setUserId(userId.longValue());
userInfoService.updateById(user);
return Result.success();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment