5
5
import com .juzi .oerp .common .exception .AuthenticationException ;
6
6
import com .juzi .oerp .mapper .UserMapper ;
7
7
import com .juzi .oerp .model .dto .ChangePasswordDTO ;
8
- import com .juzi .oerp .model .dto .RetrieveUserDTO ;
9
8
import com .juzi .oerp .model .dto .UserPasswordLoginDTO ;
10
9
import com .juzi .oerp .model .dto .UserRegistionDTO ;
11
10
import com .juzi .oerp .model .dto .UserSMSLoginDTO ;
12
11
import com .juzi .oerp .model .dto .param .CheckImageCaptchaParamDTO ;
13
12
import com .juzi .oerp .model .dto .param .CheckSMSCaptchaParamDTO ;
13
+ import com .juzi .oerp .model .dto .param .ResetPasswordParamDTO ;
14
14
import com .juzi .oerp .model .dto .param .SMSCaptchaParamDTO ;
15
15
import com .juzi .oerp .model .po .UserPO ;
16
16
import com .juzi .oerp .model .vo .CaptchaVO ;
29
29
import org .springframework .web .bind .annotation .RequestMapping ;
30
30
import org .springframework .web .bind .annotation .RestController ;
31
31
32
+ import javax .validation .constraints .Pattern ;
33
+
32
34
/**
33
35
* @author Juzi
34
36
* @date 2020/7/14 14:40
@@ -43,83 +45,90 @@ public class AuthenticationController {
43
45
@ Autowired
44
46
private UserMapper userMapper ;
45
47
46
- @ PostMapping ("/login" )
47
- @ ApiOperation (value = "密码登录" , tags = "登录注册" )
48
- public ResponseVO <UserLoginVO > loginByPassword (@ RequestBody @ Validated UserPasswordLoginDTO userPasswordLoginDTO ) {
49
- UserLoginVO result = authenticationService .loginByPassword (userPasswordLoginDTO );
50
- return new ResponseVO <>(result );
51
- }
52
-
53
- @ PostMapping ("/login/sms" )
54
- @ ApiOperation (value = "短信登录" , tags = "登录注册" )
55
- public ResponseVO <UserLoginVO > loginBySMS (@ RequestBody UserSMSLoginDTO userSMSLoginDTO ) {
56
- UserLoginVO result = authenticationService .loginBySMS (userSMSLoginDTO );
57
- return new ResponseVO <>(result );
58
- }
59
-
60
- @ PostMapping ("/registion" )
61
- @ ApiOperation (value = "账号注册" , tags = "登录注册" )
62
- public ResponseVO <UserLoginVO > registion (@ RequestBody UserRegistionDTO userRegistionDTO ) {
63
- UserLoginVO result = authenticationService .registion (userRegistionDTO );
64
- return new ResponseVO <>(result );
65
- }
66
-
67
48
@ GetMapping ("/captcha/image" )
68
49
@ ApiOperation (value = "获取图片验证码" , tags = "验证码" )
69
50
public ResponseVO <CaptchaVO > getImageCaptcha () {
70
51
CaptchaVO captcha = authenticationService .getImageCaptcha ();
71
52
return new ResponseVO <>(captcha );
72
53
}
73
54
74
- @ PostMapping ("/captcha/image" )
55
+ @ PostMapping ("/captcha/image/check " )
75
56
@ ApiOperation (value = "校验图片验证码" , tags = "验证码" )
76
- public MessageResponseVO checkImageCaptcha (@ RequestBody CheckImageCaptchaParamDTO checkImageCaptchaParamDTO ) {
57
+ public MessageResponseVO checkImageCaptcha (@ RequestBody @ Validated CheckImageCaptchaParamDTO checkImageCaptchaParamDTO ) {
77
58
authenticationService .checkImageCaptcha (checkImageCaptchaParamDTO );
78
59
return new MessageResponseVO (20001 );
79
60
}
80
61
81
62
@ PostMapping ("/captcha/sms" )
82
63
@ ApiOperation (value = "获取短信验证码" , tags = "验证码" )
83
- public MessageResponseVO getSMSCaptcha (@ RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO ) throws JsonProcessingException {
64
+ public MessageResponseVO getSMSCaptcha (@ RequestBody @ Validated SMSCaptchaParamDTO smsCaptchaParamDTO ) throws JsonProcessingException {
84
65
authenticationService .getSMSCaptcha (smsCaptchaParamDTO );
85
66
return new MessageResponseVO (20002 );
86
67
}
87
68
88
69
@ PostMapping ("/captcha/sms/check" )
89
70
@ ApiOperation (value = "校验短信验证码" , tags = "验证码" )
90
- public MessageResponseVO checkSMSCaptcha (@ RequestBody CheckSMSCaptchaParamDTO checkSMSCaptchaParamDTO ) {
71
+ public MessageResponseVO checkSMSCaptcha (@ RequestBody @ Validated CheckSMSCaptchaParamDTO checkSMSCaptchaParamDTO ) {
91
72
authenticationService .checkSMSCaptcha (checkSMSCaptchaParamDTO );
92
73
return new MessageResponseVO (20001 );
93
74
}
94
75
95
- @ PutMapping ("/password" )
76
+ @ PostMapping ("/login/password" )
77
+ @ ApiOperation (value = "密码登录" , tags = "登录注册" )
78
+ public ResponseVO <UserLoginVO > loginByPassword (@ RequestBody @ Validated UserPasswordLoginDTO userPasswordLoginDTO ) {
79
+ UserLoginVO result = authenticationService .loginByPassword (userPasswordLoginDTO );
80
+ return new ResponseVO <>(result );
81
+ }
82
+
83
+ @ PostMapping ("/login/sms" )
84
+ @ ApiOperation (value = "短信登录" , tags = "登录注册" )
85
+ public ResponseVO <UserLoginVO > loginBySMS (@ RequestBody @ Validated UserSMSLoginDTO userSMSLoginDTO ) {
86
+ UserLoginVO result = authenticationService .loginBySMS (userSMSLoginDTO );
87
+ return new ResponseVO <>(result );
88
+ }
89
+
90
+ @ PostMapping ("/registion" )
91
+ @ ApiOperation (value = "账号注册" , tags = "登录注册" )
92
+ public ResponseVO <UserLoginVO > registion (@ RequestBody @ Validated UserRegistionDTO userRegistionDTO ) {
93
+ UserLoginVO result = authenticationService .registion (userRegistionDTO );
94
+ return new ResponseVO <>(result );
95
+ }
96
+
97
+ @ PutMapping ("/password/change/old-password" )
96
98
@ ApiOperation (value = "修改密码" , notes = "通过原密码修改密码" , tags = "账户信息" )
97
- public MessageResponseVO updatePassword (@ RequestBody ChangePasswordDTO changePasswordDTO ) {
98
- authenticationService .updatePassword (changePasswordDTO );
99
+ public MessageResponseVO updatePasswordByOldPassword (@ RequestBody @ Validated ChangePasswordDTO changePasswordDTO ) {
100
+ authenticationService .updatePasswordByOldPassword (changePasswordDTO );
101
+ return new MessageResponseVO (20010 );
102
+ }
103
+
104
+ @ PutMapping ("/password/reset/sms" )
105
+ @ ApiOperation (value = "重置密码" , notes = "通过短信验证码重置密码" , tags = "账户信息" )
106
+ public MessageResponseVO resetPassword (@ RequestBody @ Validated ResetPasswordParamDTO resetPasswordParamDTO ) {
107
+ authenticationService .resetPassword (resetPasswordParamDTO );
99
108
return new MessageResponseVO (20010 );
100
109
}
101
110
102
111
@ PutMapping ("/phone/{phoneNumber}" )
103
112
@ ApiOperation (value = "修改手机号" , tags = "账户信息" )
104
- public MessageResponseVO updatePhoneNumber (@ PathVariable String phoneNumber ) {
113
+ public MessageResponseVO updatePhoneNumber (
114
+ @ PathVariable
115
+ @ Pattern (regexp = "(?:(?:\\ +|00)86)?1(?:(?:3[\\ d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\ d])|(?:9[1|8|9]))\\ d{8}" , message = "手机号格式错误" )
116
+ @ Validated String phoneNumber ) {
105
117
authenticationService .updatePhoneNumber (phoneNumber );
106
118
return new MessageResponseVO (20010 );
107
119
}
108
120
109
121
@ GetMapping ("/phone/{phoneNumber}" )
110
122
@ ApiOperation (value = "检测手机号" , notes = "判断该手机号是否已经注册过" , tags = "登录注册" )
111
- public MessageResponseVO retrieveUserByPhone (@ PathVariable String phoneNumber ) {
123
+ public MessageResponseVO retrieveUserByPhone (
124
+ @ PathVariable
125
+ @ Pattern (regexp = "(?:(?:\\ +|00)86)?1(?:(?:3[\\ d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\\ d])|(?:9[1|8|9]))\\ d{8}" , message = "手机号格式错误" )
126
+ @ Validated String phoneNumber ) {
112
127
UserPO userPO = userMapper .selectOne (new LambdaQueryWrapper <UserPO >().eq (UserPO ::getPhoneNumber , phoneNumber ));
113
128
if (userPO == null ) {
114
129
throw new AuthenticationException (40010 );
115
130
}
116
131
return new MessageResponseVO (20008 );
117
132
}
118
133
119
- @ PutMapping ("/password/sms" )
120
- @ ApiOperation (value = "重置密码" , notes = "通过短信验证码重置密码" , tags = "账户信息" )
121
- public MessageResponseVO retrieveUser (@ RequestBody RetrieveUserDTO retrieveUserDTO ) {
122
- authenticationService .resetPassword (retrieveUserDTO );
123
- return new MessageResponseVO (20010 );
124
- }
125
134
}
0 commit comments