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 00:41:28 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b8c797d84defdad32cb1f9a60af274d34e87be4a
b8c797d8
1 parent
e3ea3214
update findEmail
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
19 deletions
back/src/api/User/findEmail/findEmail.graphql
back/src/api/User/findEmail/findEmail.js
back/src/api/User/findEmail/findEmail.graphql
View file @
b8c797d
type Query {
findEmail(phoneNum
ber: String!): String
!
findEmail(phoneNum
: String!): Boolean
!
}
...
...
back/src/api/User/findEmail/findEmail.js
View file @
b8c797d
import
{
prisma
,
generateSecret
,
isAuthenticated
}
from
"../../../utils"
;
import
{
prisma
,
isAuthenticated
}
from
"../../../utils"
;
import
twilio
from
"twilio"
;
export
default
{
Query
:
{
findEmail
:
async
(
_
,
args
)
=>
{
if
(
isAuthenticated
)
{
const
{
phoneNumber
}
=
args
;
const
{
phoneNum
}
=
args
;
const
user
=
await
prisma
.
user
.
findOne
({
where
:
{
phoneNum
,
},
});
if
(
user
&&
isAuthenticated
)
{
const
accountSid
=
process
.
env
.
TWILIO_SID
;
const
authToken
=
process
.
env
.
TWILIO_AUTH_TOKEN
;
const
twilioPhone
=
process
.
env
.
TWILIO_PHONE_NUMBER
;
const
client
=
new
twilio
(
accountSid
,
authToken
);
const
randomWords
=
generateSecret
();
client
.
messages
.
create
({
body
:
`
Please enter this word :
${
randomWords
}
`
,
to
:
`
${
phoneNum
ber
}
`
,
from
:
"KhuChat"
,
body
:
`
Your Email is :
${
user
.
email
}
`
,
to
:
`
${
phoneNum
}
`
,
from
:
`
${
twilioPhone
}
`
,
})
.
then
((
message
)
=>
{
console
.
log
(
message
.
sid
);
console
.
log
(
" --- "
+
message
);
});
const
user
=
await
prisma
.
user
.
update
({
where
:
{
phoneNumber
,
},
data
:
{
phoneSecret
:
randomWords
,
},
});
return
user
.
email
;
return
true
;
}
else
{
throw
new
Error
(
"You need to login first"
);
}
...
...
Please
register
or
login
to post a comment