licailing hace 5 años
padre
commit
ebc5a10a1c

+ 10 - 2
src/main/java/com/izouma/dingdong/service/UserService.java

@@ -254,13 +254,21 @@ public class UserService {
     /*
     更新密码
      */
-    public String setPassword(Long userId, String key, String code, String password) {
+    public String setPassword(String key, String code, String password,Identity identity) {
         try {
             smsService.verify(key, code);
         } catch (SmsService.SmsVerifyException e) {
             e.printStackTrace();
             throw new BusinessException("验证码错误");
         }
-        return setPassword(userId, password);
+
+        User user = userRepo.findByPhoneAndIdentity(key, identity);
+        if (user==null){
+            throw new BusinessException("无用户");
+        }
+        user.setPassword(new BCryptPasswordEncoder().encode(password));
+        user = userRepo.save(user);
+        return jwtTokenUtil.generateToken(JwtUserFactory.create(user));
+
     }
 }

+ 3 - 2
src/main/java/com/izouma/dingdong/web/UserController.java

@@ -131,8 +131,9 @@ public class UserController extends BaseController {
 
     @PostMapping("/changePassword")
     @ApiOperation("修改密码")
-    public String changePassword(@RequestParam String password, @RequestParam String key, @RequestParam String code) {
-        return userService.setPassword(SecurityUtils.getAuthenticatedUser().getId(), key, code, password);
+    public String changePassword(@RequestParam String password, @RequestParam String key,
+                                 @RequestParam String code, @RequestParam Identity identity) {
+        return userService.setPassword(key, code, password, identity);
     }
 
 }