Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
long-tern-care-service
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hubin
long-tern-care-service
Commits
ae9c7eac
Commit
ae9c7eac
authored
Mar 06, 2023
by
“xuhd”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
密码修改
parent
5a6aa1e7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
0 deletions
+38
-0
UserController.java
...va/com/hungraim/ltc/system/controller/UserController.java
+38
-0
No files found.
system/system-admin-service/src/main/java/com/hungraim/ltc/system/controller/UserController.java
View file @
ae9c7eac
...
@@ -20,6 +20,7 @@ import com.hungraim.ltc.util.Result;
...
@@ -20,6 +20,7 @@ import com.hungraim.ltc.util.Result;
import
com.hungraim.ltc.util.ResultCode
;
import
com.hungraim.ltc.util.ResultCode
;
import
com.hungraim.ltc.util.TokenParsingUtil
;
import
com.hungraim.ltc.util.TokenParsingUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -295,6 +296,43 @@ public class UserController {
...
@@ -295,6 +296,43 @@ public class UserController {
return
Result
.
success
(
"更新成功"
);
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
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment