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 17:15:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ab69e41c4a33a962dd4b5b08d3f3b329c805d77a
ab69e41c
1 parent
b8196d85
update sendmail
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
back/src/utils.js
back/src/utils.js
View file @
ab69e41
import
dotenv
from
"dotenv"
;
dotenv
.
config
();
import
{
PrismaClient
}
from
"@prisma/client"
;
import
{
nouns
,
adjectives
}
from
"./words"
;
import
jwt
from
"jsonwebtoken"
;
import
nodemailer
from
"nodemailer
"
;
import
sgTransport
from
"nodemailer-sendgrid-transport"
;
import
sgMail
from
"@sendgrid/mail
"
;
sgMail
.
setApiKey
(
process
.
env
.
SENDGRID_API_KEY
)
;
export
const
prisma
=
new
PrismaClient
();
...
...
@@ -25,7 +27,7 @@ export const isAuthenticated = (request) => {
export
const
changePhoneNumber
=
(
phoneNum
,
locationNum
)
=>
{
var
leftStr
=
locationNum
;
var
rightStr
=
phoneNum
.
slice
(
1
,
phoneNum
.
length
()
);
var
rightStr
=
phoneNum
.
slice
(
1
,
phoneNum
.
length
);
var
newStr
=
leftStr
+
rightStr
;
return
newStr
;
};
...
...
@@ -35,25 +37,26 @@ export const generateSecret = () => {
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
generateToken
=
(
id
)
=>
jwt
.
sign
({
id
},
process
.
env
.
JWT_SECRET
);
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.
`
,
export
const
createEMessage
=
(
userEmail
,
emailSecret
)
=>
{
const
email
Message
=
{
to
:
`
${
userEmail
}
`
,
from
:
"KhuChat@KhuChat.com"
,
subject
:
"Email from KhuChat"
,
html
:
`
We send email for reset your password, enter this key : <b>
${
emailSecret
}
</b>
`
,
};
return
sendEmail
(
email
)
;
return
emailMessage
;
};
export
const
generateToken
=
(
id
)
=>
jwt
.
sign
({
id
},
process
.
env
.
JWT_SECRET
);
export
const
sendEmail
=
(
userEmail
,
emailSecret
)
=>
{
sgMail
.
send
(
createEMessage
(
userEmail
,
emailSecret
)).
then
(
()
=>
{},
(
error
)
=>
{
console
.
error
(
error
);
if
(
error
.
response
)
{
console
.
error
(
error
.
response
.
body
);
}
}
);
};
...
...
Please
register
or
login
to post a comment