明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
letian_backend
Project
Project
Details
Activity
Releases
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
zengfanpei
letian_backend
Commits
41325eb9
Commit
41325eb9
authored
Oct 21, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:用户密码
parent
89e84bc2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
0 deletions
+36
-0
userController.js
controller/userController.js
+34
-0
userRouter.js
router/userRouter.js
+2
-0
No files found.
controller/userController.js
View file @
41325eb9
...
...
@@ -173,7 +173,39 @@ async function checkUserToken(req, res, next) {
}
}
// 用于登录后更新密码,
async
function
changePassword
(
req
,
res
,
next
)
{
try
{
let
user
=
req
.
user
;
let
newPassword
=
req
.
body
.
newPassword
;
const
{
salt
,
passwordHash
}
=
utils
.
saltHashPassword
(
newPassword
);
const
ret
=
await
userModule
.
findOneAndUpdate
({
_id
:
user
.
_id
},
{
// ...req.body,
salt
,
password
:
passwordHash
});
await
ioRedis
.
del
(
`token:
${
user
.
token
}
`
)
res
.
sendData
(
req
.
user
);
}
catch
(
error
)
{
next
(
error
);
}
}
// changePwd 用于管理员修改成员密码,不影响成员当前这一次的登录状态,下次登录需要用新密码登录。
async
function
changePwd
(
req
,
res
,
next
)
{
try
{
const
{
salt
,
passwordHash
}
=
utils
.
saltHashPassword
(
"123456"
);
const
ret
=
await
userModule
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
// ...req.body,
salt
,
password
:
passwordHash
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
...
...
@@ -363,6 +395,8 @@ module.exports = {
getRole
,
deleteUser
,
checkUserToken
,
changePassword
,
changePwd
,
createRole
,
listRole
,
...
...
router/userRouter.js
View file @
41325eb9
...
...
@@ -10,12 +10,14 @@ router.post('/regist', userController.regist);
router
.
post
(
'/login'
,
userController
.
login
);
router
.
post
(
'/checkUserToken'
,
userController
.
checkUserToken
);
router
.
post
(
'/changePassword'
,
userController
.
changePassword
);
router
.
post
(
'/manage/list'
,
userController
.
listUser
);
router
.
post
(
'/manage/create'
,
userController
.
addUser
);
router
.
post
(
'/manage/update'
,
userController
.
updateUser
);
//更新
router
.
post
(
'/manage/info'
,
userController
.
getUser
);
router
.
post
(
'/manage/delete'
,
userController
.
deleteUser
);
// 删除
router
.
post
(
'/manage/changePwd'
,
userController
.
changePwd
);
// 删除
/**
...
...
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