Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const transporter = nodemailer.createTransport({
- service: 'gmail',
- secure: false,
- port: 25,
- auth : {
- user: "",//hided
- pass: ""//hided
- },
- tls: {
- rejectUnauthorized: false
- }
- })
- exports.registerController = (req,res) => {
- const{name , email , password} = req.body
- //Extracts the validation errors from a request and makes them available in a Result object.
- const errors = validationResult(req);
- if (!errors.isEmpty()) {
- const firstError = errors.array().map(error => error.msg)[0]
- return res.status(422).json({
- error: firstError
- })
- }
- else{
- User.findOne({
- email
- }).exec((err , user) => {
- //If user exists
- if(user) {
- return res.status(400).json({
- error: "Email is taken"
- })
- }
- })
- //Generate Token
- const token = jwt.sign({
- name,
- email,
- password
- },
- process.env.JWT_ACCOUNT_ACTIVATION,
- {
- expiresIn: '15min'
- }
- )
- const emailDataRegistration = {
- from: process.env.EMAIL_FROM,
- to : email,
- subject: "Account activation link",
- hmtl: `
- <h1>Please Click on link to activate </h1>
- <p>${process.env.CLIENT_URL}/activate/${token}</p>
- <hr/>
- <p>This email contain sensitive info</p>
- <p>${process.env.CLIENT_URL}
- `
- }
- transporter.sendMail(emailDataRegistration , function(err,info) {
- if(err){
- console.log(err)
- return;
- }
- console.log("Sent: " + info.response)
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement