-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft #164489783 integrating sendgrid to send email
- Loading branch information
Frank Harerimana
authored and
Frank Harerimana
committed
Apr 10, 2019
1 parent
c72ba96
commit d9b2156
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); }) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters