Skip to content

Commit

Permalink
ft #164489783 integrating sendgrid to send email
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Harerimana authored and Frank Harerimana committed Apr 10, 2019
1 parent c72ba96 commit d9b2156
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
18 changes: 18 additions & 0 deletions middlewares/sendMail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sgMail from '@sendgrid/mail';
import dotenv from 'dotenv';

dotenv.config();

const sender = (to, subject, message) => {
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to,
from: 'harfrank2@gmail.com',
subject,
text: message,
html: '<strong>email fired up</strong>',
};
sgMail.send(msg);
return 'success';
};
export default sender;
38 changes: 38 additions & 0 deletions migrations/20190410060956-create-resetpassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('resetpassword', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
type: Sequelize.INTEGER
},
token: {
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
}).then(() => {
console.log('created resetpassword table');
return queryInterface.sequelize.query(`
CREATE EVENT expireLink
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 DAY
DO
DELETE FROM resetpassword WHERE createdAt < DATE_SUB(NOW(), INTERVAL 1 DAY);
`);
}).then(() => { console.log('expireToken event created'); }),
down: (queryInterface, Sequelize) => queryInterface.dropTable('resetpassword')
.then(() => {
console.log('reset password token dropped');
return queryInterface.sequelize.query('DROP EVENT IF EXISTS expireLink');
}).then(() => { console.log('event dropped'); })
};
19 changes: 19 additions & 0 deletions models/resetpassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


module.exports = (sequelize, DataTypes) => {
const resetpassword = sequelize.define('resetpassword', {
userId: DataTypes.INTEGER,
token: DataTypes.STRING
}, {
classMethods: {
associate(models) {
resetpassword.belongsTo(models.User, {
as: 'id',
foreignKey: 'userId',
foreignKeyConstraint: true
});
}
}
});
return resetpassword;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@babel/core": "^7.4.0",
"@babel/node": "^7.2.2",
"@babel/preset-env": "^7.4.2",
"@sendgrid/mail": "^6.3.1",
"body-parser": "^1.18.3",
"config": "^3.0.1",
"cors": "^2.8.4",
Expand Down

0 comments on commit d9b2156

Please sign in to comment.