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;
...
@@ -13,6 +13,7 @@ const dataSource = myDataSource;
/**Make requiest to init recovery process */
/**Make requiest to init recovery process */
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
|
Response
>=>
{
router
.
post
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
void
|
Response
>=>
{
try
{
const
{
email
}
=
req
.
body
const
{
email
}
=
req
.
body
console
.
log
(
"emeil"
,
email
)
console
.
log
(
"emeil"
,
email
)
const
user
=
await
dataSource
const
user
=
await
dataSource
...
@@ -25,7 +26,6 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
...
@@ -25,7 +26,6 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
console
.
log
(
'user '
,
user
)
console
.
log
(
'user '
,
user
)
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
if
(
!
user
)
return
res
.
status
(
404
).
send
({
message
:
'user not found'
})
const
token
=
nanoid
();
const
token
=
nanoid
();
try
{
const
passwordRecovery
=
new
PasswordRecovery
()
const
passwordRecovery
=
new
PasswordRecovery
()
passwordRecovery
.
user
=
user
;
passwordRecovery
.
user
=
user
;
passwordRecovery
.
token
=
token
;
passwordRecovery
.
token
=
token
;
...
@@ -50,6 +50,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
...
@@ -50,6 +50,7 @@ router.post ('/', async (req:Request, res:Response):Promise<void |Response>=>{
/**reset token in password recovery */
/**reset token in password recovery */
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
router
.
get
(
'/'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
try
{
const
token
=
req
.
query
.
token
;
const
token
=
req
.
query
.
token
;
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
if
(
!
token
)
return
res
.
status
(
401
).
send
({
Message
:
'token not exists'
})
const
passwordRecovery
=
await
dataSource
const
passwordRecovery
=
await
dataSource
...
@@ -62,16 +63,16 @@ router.get('/', async(req: Request, res: Response):Promise<Response|void>=>{
...
@@ -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"
})
if
(
!
passwordRecovery
||
!
passwordRecovery
.
enabled
)
return
res
.
status
(
404
).
send
({
message
:
"Token is not valid"
})
res
.
send
(
passwordRecovery
)
res
.
send
(
passwordRecovery
)
passwordRecovery
.
enabled
=
false
;
passwordRecovery
.
enabled
=
false
;
try
{
await
passwordRecovery
.
save
();
await
passwordRecovery
.
save
();
}
catch
(
e
){
}
catch
(
e
)
{
console
.
log
(
e
)
return
res
.
status
(
502
).
send
({
message
:(
e
as
Error
).
message
}
)
}
}
})
})
/**change password */
/**change password */
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
router
.
patch
(
'/:id/change-password'
,
async
(
req
:
Request
,
res
:
Response
):
Promise
<
Response
|
void
>=>
{
try
{
const
user
=
await
dataSource
const
user
=
await
dataSource
.
getRepository
(
User
)
.
getRepository
(
User
)
.
findOneBy
({
id
:
req
.
params
.
id
})
.
findOneBy
({
id
:
req
.
params
.
id
})
...
@@ -79,7 +80,6 @@ router.patch('/:id/change-password', async (req: Request, res: Response):Promise
...
@@ -79,7 +80,6 @@ router.patch('/:id/change-password', async (req: Request, res: Response):Promise
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
const
salt
=
await
bcrypt
.
genSalt
(
SALT_WORK_FACTOR
);
const
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
const
newPassword
:
string
=
await
bcrypt
.
hash
(
req
.
body
.
password
,
salt
);
user
.
password
=
newPassword
user
.
password
=
newPassword
try
{
await
user
.
save
()
await
user
.
save
()
res
.
send
({
message
:
"Password saved"
})
res
.
send
({
message
:
"Password saved"
})
}
catch
(
e
){
}
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