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-23 21:50:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c0146f1e986d58253da1a25d6a3342c9cd97220a
c0146f1e
1 parent
2bdfe811
add packages (email, jwt)
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletions
back/src/utils.js
back/src/utils.js
View file @
c0146f1
import
jwt
from
"jsonwebtoken"
;
import
{
PrismaClient
}
from
"@prisma/client"
;
import
{
nouns
,
adjectives
}
from
"./words"
;
import
jwt
from
"jsonwebtoken"
;
import
nodemailer
from
"nodemailer"
;
import
sgTransport
from
"nodemailer-sendgrid-transport"
;
export
const
prisma
=
new
PrismaClient
();
...
...
@@ -12,3 +15,31 @@ export const getUserId = (context) => {
}
throw
new
Error
(
"There is no vaild user"
);
};
export
const
generateSecret
=
()
=>
{
const
randomNumber
=
Math
.
floor
(
Math
.
random
()
*
adjectives
.
length
);
return
`
${
adjectives
[
randomNumber
]}
${
nouns
[
randomNumber
]}
`
;
};
const
sendEmail
=
(
email
)
=>
{
const
options
=
{
auth
:
{
api_user
:
process
.
env
.
SENDGRID_USERNAME
,
api_password
:
process
.
env
.
SENDGRID_PASSWORD
,
},
};
const
client
=
nodemailer
.
createTransport
(
sgTransport
(
options
));
return
client
.
sendMail
(
email
);
};
export
const
sendSecretMail
=
(
address
,
emailSecret
,
value
)
=>
{
const
email
=
{
from
:
"vel1024@khu.ac.kr"
,
to
:
address
,
subject
:
`Authentication key for forgotten
${
value
}
`
,
html
:
`Hello, This is khuchat, authentication key is <b>
${
emailSecret
}
</b>, copy and paste it, Thanks.`
,
};
return
sendEmail
(
email
);
};
export
const
generateToken
=
(
id
)
=>
jwt
.
sign
({
id
},
process
.
env
.
JWT_SECRET
);
...
...
Please
register
or
login
to post a comment