Selaa lähdekoodia

add 修改密码

A17404李放 3 vuotta sitten
vanhempi
commit
66ed599046

+ 27 - 0
nb-admin/src/main/java/com/coffee/admin/controller/system/SysLoginController.java

@@ -2,11 +2,20 @@ package com.coffee.admin.controller.system;
 
 import cn.dev33.satoken.stp.StpUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.coffee.admin.controller.system.vo.UserPassVo;
 import com.coffee.common.annotation.Log;
 import com.coffee.common.dto.LoginDTO;
+import com.coffee.common.exception.CustomException;
 import com.coffee.common.result.R;
+import com.coffee.common.util.SecurityUtil;
 import com.coffee.framework.web.service.IUserService;
 import com.coffee.system.common.vo.AccountInfoVO;
+import com.coffee.system.entity.SysUser;
+import com.coffee.system.service.ISysUserService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -28,6 +37,8 @@ public class SysLoginController {
     @Resource
     IUserService userService;
 
+    @Resource
+    ISysUserService sysUserService;
     @Log(title = "登录")
     @PostMapping("/login")
     public R login(@Validated @RequestBody LoginDTO req) {
@@ -37,6 +48,22 @@ public class SysLoginController {
         return R.success(result);
     }
 
+    @ApiOperation("修改密码")
+    @PostMapping(value = "/updatePass")
+    public ResponseEntity<Object> updatePass(@RequestBody @Validated UserPassVo passVo) throws Exception {
+        // 密码解密
+        Long userId = SecurityUtil.getSysUser().getId();
+        SysUser sysUser = sysUserService.getById(userId);
+        if (!SecurityUtil.matchesPassword(passVo.getOldPass(), sysUser.getPassword())) {
+            throw new CustomException("旧密码不正确");
+        }
+        String encryptPassword = SecurityUtil.encryptPassword(sysUser.getPassword());
+        sysUserService
+                .update(new UpdateWrapper<SysUser>()
+                        .lambda().eq(SysUser::getId,userId)
+                        .set(SysUser::getPassword,encryptPassword));
+        return new ResponseEntity<>(HttpStatus.OK);
+    }
     @Log(title = "获取用户信息")
     @GetMapping("/getUserInfo")
     public R getUserInfo() {

+ 37 - 0
nb-admin/src/main/java/com/coffee/admin/controller/system/vo/UserPassVo.java

@@ -0,0 +1,37 @@
+/*
+ *  Copyright 2019-2020 Zheng Jie
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package com.coffee.admin.controller.system.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * 修改密码的 Vo 类
+ * @author Zheng Jie
+ * @date 2019年7月11日13:59:49
+ */
+@Data
+@ApiModel("密码修改")
+public class UserPassVo {
+    @ApiModelProperty("旧密码")
+    private String oldPass;
+    @ApiModelProperty("新密码")
+    @NotBlank(message = "新密码不能为空")
+    private String newPass;
+}