Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-04-25 23:09:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a3647b7c39c5f2db3db6d53c0a451cd8034d0e87
a3647b7c
1 parent
88b1c139
add isAuthenticated middleware
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
26 deletions
back/src/api/User/resetPassword/resetPassword.js
back/src/api/User/resetPassword/resetPassword.js
View file @
a3647b7
import
{
prisma
}
from
"../../../utils"
;
import
{
prisma
,
isAuthenticated
}
from
"../../../utils"
;
import
bcrypt
from
"bcryptjs"
;
export
default
{
Mutation
:
{
resetPassword
:
async
(
_
,
args
)
=>
{
const
{
secret
,
email
,
passwordOne
,
passwordTwo
}
=
args
;
const
user
=
await
prisma
.
user
.
findOne
({
where
:
{
email
,
},
});
const
encryptSecret
=
await
bcrypt
.
hash
(
user
.
emailSecret
,
10
);
if
(
encryptSecret
!==
secret
)
{
throw
new
Error
(
"not vaild secret value!, input another value or resend email"
);
}
else
{
if
(
passwordOne
!==
passwordTwo
)
{
// For check new password is right, the two things must be same.
throw
new
Error
(
"the two password don't match each other, try again"
);
if
(
isAuthenticated
)
{
const
{
secret
,
email
,
passwordOne
,
passwordTwo
}
=
args
;
const
user
=
await
prisma
.
user
.
findOne
({
where
:
{
email
,
},
});
const
encryptSecret
=
await
bcrypt
.
hash
(
user
.
emailSecret
,
10
);
if
(
encryptSecret
!==
secret
)
{
throw
new
Error
(
"not vaild secret value!, input another value or resend email"
);
}
else
{
await
prisma
.
user
.
update
({
where
:
{
email
,
},
data
:
{
emailSecret
:
""
,
password
:
passwordOne
,
},
});
if
(
passwordOne
!==
passwordTwo
)
{
// For check new password is right, the two things must be same.
throw
new
Error
(
"the two password don't match each other, try again"
);
}
else
{
await
prisma
.
user
.
update
({
where
:
{
email
,
},
data
:
{
emailSecret
:
""
,
password
:
passwordOne
,
},
});
}
return
user
;
}
return
user
;
}
else
{
throw
new
Error
(
"You need to login first"
);
}
},
},
...
...
Please
register
or
login
to post a comment