Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
planner-team-one
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
21
Issues
21
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
Евгений Положенцев
planner-team-one
Commits
9e80d81e
Commit
9e80d81e
authored
Jan 17, 2023
by
Евгений Положенцев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#151
added try blocks to passwordRecovery.ts
parent
3132fbbd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
passwordRecovery.ts
planner-api/src/routers/passwordRecovery.ts
+6
-6
No files found.
planner-api/src/routers/passwordRecovery.ts
View file @
9e80d81e
...
...
@@ -13,6 +13,7 @@ const dataSource = myDataSource;
/**Make requiest to init recovery process */
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
|
Response
>=>
{
try
{
const
{
email
}
=
req
.
body
console
.
log
(
"emeil"
,
email
)
const
user
=
await
dataSource
...
...
@@ -25,7 +26,6 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
console
.
log
(
'user '
,
user
)
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
const
token
=
nanoid
();
try
{
const
passwordRecovery
=
new
PasswordRecovery
()
passwordRecovery
.
user
=
user
;
passwordRecovery
.
token
=
token
;
...
...
@@ -50,6 +50,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
/**reset token in password recovery */
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
try
{
const
token
=
req
.
query
.
token
;
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
const
passwordRecovery
=
await
dataSource
...
...
@@ -62,16 +63,16 @@ router.get('/', async(req: Request, res: Response):Promise<Response|void>=>{
if
(
!
passwordRecovery
||
!
passwordRecovery
.
enabled
)
return
res
.
status
(
404
).
send
({
message
:
"Token is not valid"
})
res
.
send
(
passwordRecovery
)
passwordRecovery
.
enabled
=
false
;
try
{
await
passwordRecovery
.
save
();
}
catch
(
e
){
console
.
log
(
e
)
}
}
catch
(
e
)
{
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
}
)
}
})
/**change password */
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
try
{
const
user
=
await
dataSource
.
getRepository
(
User
)
.
findOneBy
({
id
:
req
.
params
.
id
})
...
...
@@ -79,7 +80,6 @@ router.patch('/:id/change-password', async (req: Request, res: Response):Promise
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
const
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
user
.
password
=
newPassword
try
{
await
user
.
save
()
res
.
send
({
message
:
"Password saved"
})
}
catch
(
e
){
...
...
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