-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(authenication): implement password reset
- user receives link to reset password via email - user can reset password with the link received via email - user can only use the link received via email once [Delivers #159987402]
- Loading branch information
1 parent
b37f5d4
commit 182ca63
Showing
11 changed files
with
350 additions
and
28 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
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
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,34 @@ | ||
export default { | ||
verifiedMessage: ` | ||
<div> | ||
<p>Hurry!!!!</p> | ||
<p>You have successfully verified your account, and | ||
we are supper exited to have you on our platform | ||
Thanks! | ||
</p> | ||
</div>`, | ||
msgOnRegistration: (username, url, token) => ` | ||
<div> | ||
<h3>Hi ${username},</h3> | ||
<p>Welcome to Author's Haven, we extend our gratitude to | ||
to have you on our platform, But to activate your account please | ||
click on this link <br /> | ||
<br /> <br /> | ||
<a href="${url}/api/verify/${token}" | ||
style="border: 1px solid light-blue; background-color: blue; padding: 10px; | ||
color: #fff; border-radius:10px; text-decoration: none" > Verify Account | ||
<a> | ||
</p> | ||
</div>`, | ||
|
||
msgForPasswordReset: (username, url, token) => ` | ||
<div> | ||
<h3>Hi ${username},</h3> | ||
<p>You requested for a Password reset on your account. You can use the following link to reset your password: | ||
<br /> | ||
<br /> <br /> | ||
<a href="${url}/api/v1/users/api/auth/reset-password/${token}">${url}/api/v1/users/api/auth/reset-password/${token}</a> | ||
</p> | ||
<p>If you don’t use this link within 3 hours, it will expire. To get a new password reset link, visit <a href="${url}/api/v1/users/api/auth/reset-password/">${url}/api/v1/users/api/auth/reset-password/</a></p> | ||
</div>` | ||
}; |
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
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
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,68 @@ | ||
import { config } from 'dotenv'; | ||
import sgMail from '@sendgrid/mail'; | ||
import emsg from './eMsgs'; | ||
|
||
config(); | ||
const secret = process.env.SENDGRID_API_KEY; | ||
sgMail.setApiKey(secret); | ||
const url = process.env.BASE_URL; | ||
const { msgOnRegistration } = emsg; | ||
|
||
/** | ||
* Mailer Event Emitter | ||
* @exports | ||
* @class Mailer | ||
*/ | ||
export default class Mailer { | ||
/** | ||
* Email Transporter | ||
* @method sender | ||
* @memberof Mailer | ||
* @param {string} email | ||
* @param {string} subject | ||
* @param {string} message | ||
* @returns {nothing} returns nothing | ||
*/ | ||
static sender({ to, subject, message }) { | ||
const msg = { | ||
to, | ||
from: 'noreply@metis-ah', | ||
subject, | ||
html: message, | ||
}; | ||
return sgMail.send(msg); | ||
} | ||
|
||
/** | ||
* Sends Mail on user registration | ||
* @method onUserRegistration | ||
* @memberof Mailer | ||
* @param {string} username | ||
* @param {string} email user's email | ||
* @param {string} token user's token | ||
* @returns {function} sender | ||
*/ | ||
static onUserRegistration(username, email, token) { | ||
return Mailer.sender({ | ||
to: email, | ||
subject: 'Verify user\'s account', | ||
message: msgOnRegistration(username, url, token) | ||
}); | ||
} | ||
|
||
/** | ||
* Email Sender helper function | ||
* @method emailHelperfunc | ||
* @memberof Mailer | ||
* @param {*} args | ||
* @returns {function} sender | ||
*/ | ||
static emailHelperfunc(args) { | ||
const { email, subject, message } = args; | ||
return Mailer.sender({ | ||
to: email, | ||
subject, | ||
message | ||
}); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import express from 'express'; | ||
import userController from '../controllers/userController'; | ||
import usersValidations from '../middleware/usersValidations'; | ||
import auth from '../middleware/auth'; | ||
|
||
const { validateSignUp, validateLogin } = usersValidations; | ||
const { validateSignUp, validateLogin, validateNewPassword } = usersValidations; | ||
|
||
const userRoutes = express.Router(); | ||
|
||
userRoutes.post('/auth/signup', validateSignUp, userController.signUp); | ||
userRoutes.post('/auth/login', validateLogin, userController.login); | ||
userRoutes.post('/api/auth/reset-password', userController.resetPassword); | ||
userRoutes.put('/api/auth/reset-password/:token', auth, validateNewPassword, userController.reset); | ||
|
||
export default userRoutes; |
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,13 @@ | ||
|
||
module.exports = { | ||
up: queryInterface => queryInterface.bulkInsert('Users', [{ | ||
username: 'username', | ||
email: 'username@gmail.com', | ||
password: 'bouhsiudgsd', | ||
isVerified: true, | ||
createdAt: '2018-09-09', | ||
updatedAt: '2018-09-09', | ||
}]), | ||
|
||
down: queryInterface => queryInterface.bulkDelete('Users', null, {}) | ||
}; |
Oops, something went wrong.