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-26 15:23:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8923f8892ed9f8668ae15b28c7f703f7c3690c05
8923f889
1 parent
56440749
rename secret to emailSecret
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
33 deletions
back/src/api/User/resetPassword/resetPassword.graphql
back/src/api/User/resetPassword/resetPassword.js
back/src/api/User/resetPassword/resetPassword.graphql
View file @
8923f88
type Mutation {
resetPassword(
s
ecret: String!
emailS
ecret: String!
email: String!
passwordOne: String!
passwordTwo: String!
...
...
back/src/api/User/resetPassword/resetPassword.js
View file @
8923f88
...
...
@@ -3,40 +3,35 @@ import bcrypt from "bcryptjs";
export
default
{
Mutation
:
{
resetPassword
:
async
(
_
,
args
)
=>
{
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"
);
resetPassword
:
async
(
_
,
args
,
{
request
})
=>
{
isAuthenticated
(
request
);
const
{
emailSecret
,
email
,
passwordOne
,
passwordTwo
}
=
args
;
const
user
=
await
prisma
.
user
.
findOne
({
where
:
{
email
,
},
});
const
encryptSecret
=
await
bcrypt
.
hash
(
user
.
emailSecret
,
10
);
if
(
encryptSecret
!==
emailSecret
)
{
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"
);
}
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"
);
}
else
{
await
prisma
.
user
.
update
({
where
:
{
email
,
},
data
:
{
emailSecret
:
""
,
password
:
passwordOne
,
},
});
}
return
user
;
await
prisma
.
user
.
update
({
where
:
{
email
,
},
data
:
{
emailSecret
:
""
,
password
:
passwordOne
,
},
});
}
}
else
{
throw
new
Error
(
"You need to login first"
);
return
user
;
}
},
},
...
...
Please
register
or
login
to post a comment