|
@@ -2,19 +2,18 @@ package com.njyunzhi.invoice.controller;
|
2
|
2
|
|
3
|
3
|
import cn.dev33.satoken.stp.StpUtil;
|
4
|
4
|
import com.njyunzhi.invoice.common.BaseController;
|
|
5
|
+import com.njyunzhi.invoice.common.EncryptUtils;
|
5
|
6
|
import com.njyunzhi.invoice.common.ResponseBean;
|
6
|
7
|
import com.njyunzhi.invoice.common.StringUtils;
|
7
|
8
|
import com.njyunzhi.invoice.entity.SysUser;
|
8
|
9
|
import com.njyunzhi.invoice.service.ISysUserService;
|
|
10
|
+import com.njyunzhi.invoice.vo.ChangePassword;
|
9
|
11
|
import com.njyunzhi.invoice.vo.LoginParm;
|
10
|
12
|
import io.swagger.annotations.Api;
|
11
|
13
|
import io.swagger.annotations.ApiOperation;
|
12
|
14
|
import io.swagger.annotations.ApiParam;
|
13
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
15
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
16
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
16
|
+import org.springframework.web.bind.annotation.*;
|
18
|
17
|
|
19
|
18
|
import java.util.HashMap;
|
20
|
19
|
import java.util.Map;
|
|
@@ -44,4 +43,35 @@ public class LoginController extends BaseController {
|
44
|
43
|
|
45
|
44
|
return ResponseBean.success(result);
|
46
|
45
|
}
|
|
46
|
+
|
|
47
|
+ @PostMapping("/admin/logout")
|
|
48
|
+ @ApiOperation(value="登出", notes = "登出", httpMethod = "POST", response = ResponseBean.class)
|
|
49
|
+ public ResponseBean logout() throws Exception {
|
|
50
|
+ StpUtil.logout();
|
|
51
|
+ return ResponseBean.success("success");
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ @PutMapping("/admin/change-password")
|
|
56
|
+ @ApiOperation(value="修改密码", notes = "修改密码", httpMethod = "PUT", response = ResponseBean.class)
|
|
57
|
+ public ResponseBean changePassword(@ApiParam("修改密码参数") @RequestBody ChangePassword param) throws Exception {
|
|
58
|
+ if (StringUtils.isEmpty(param.getOriginPassword()) || StringUtils.isEmpty(param.getNewPassword())) {
|
|
59
|
+ return ResponseBean.error("原始密码或新密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ SysUser currentUser = currentUser();
|
|
63
|
+
|
|
64
|
+ if (!checkPassword(param.getOriginPassword(), currentUser.getPassword(), currentUser.getUserId())) {
|
|
65
|
+ return ResponseBean.error("原始密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
|
|
66
|
+ }
|
|
67
|
+
|
|
68
|
+ currentUser.setPassword(EncryptUtils.md5(param.getNewPassword(), currentUser.getUserId()));
|
|
69
|
+ iSysUserService.updateById(currentUser);
|
|
70
|
+
|
|
71
|
+ return ResponseBean.success("密码修改成功");
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ private boolean checkPassword(String src, String targ, String salt) {
|
|
75
|
+ return EncryptUtils.md5(src, salt).equals(targ);
|
|
76
|
+ }
|
47
|
77
|
}
|