-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
339 additions
and
5 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
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,32 @@ | ||
import Joi from 'joi'; | ||
import Util from '../../helpers/util'; | ||
|
||
const util = new Util(); | ||
|
||
export default (req, res, next) => { | ||
const { password, confirmPassword } = req.body; | ||
|
||
if (password !== confirmPassword) { | ||
util.setError(400, 'Passwords provided do not match'); | ||
return util.send(res); | ||
} | ||
|
||
const schema = { | ||
password: Joi.string().trim().regex(/^(?:(?=.*[a-z])(?:(?=.*[A-Z])(?=.*[\d\W])|(?=.*\W)(?=.*\d))|(?=.*\W)(?=.*[A-Z])(?=.*\d)).{8,}$/).required(), | ||
}; | ||
const { error } = Joi.validate({ | ||
password | ||
}, schema); | ||
|
||
if (!error) return next(); | ||
const errorMessageFromJoi = error.details[0].message; | ||
|
||
if (errorMessageFromJoi.includes('fails to match the required pattern')) { | ||
util.setError(400, 'Password should be altleast 8 characters, Contain both uppercase and lower case and a combination of letters, numbers and symbols'); | ||
return util.send(res); | ||
} | ||
if (errorMessageFromJoi === '"password" is not allowed to be empty') { | ||
util.setError(400, 'No password was specified'); | ||
return util.send(res); | ||
} | ||
}; |
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,38 @@ | ||
import 'dotenv/config'; | ||
import sgMail from '@sendgrid/mail'; | ||
|
||
const sendEmail = (email, username, url) => { | ||
sgMail.setApiKey(process.env.SendGridApiKey); | ||
|
||
const msg = { | ||
to: `${email}`, | ||
from: `${process.env.SENDER_EMAIL}`, | ||
subject: 'How to reset your Author\'s Haven account password.', | ||
text: 'Follow this link provided to reset your password', | ||
html: `<div style="width: 90%; margin: 5rem auto; box-shadow: 0 0 10px rgba(0,0,0,.9);"> | ||
<div> | ||
<div> | ||
<div style="background-color: #2084ba; height: 3rem; width: 100%"> | ||
<h2 style="text-align: center; color: white; padding-top: 10px;">Author's Heaven</h2> | ||
</div> | ||
<h4 style="text-align: center">Hi! ${username}</h4> | ||
</div> | ||
<div style=" padding: 0px 20px 20px 20px"> | ||
<div> | ||
<p>You are recieving this because you (or someone else) requested the reset of your password for your account</p></br> | ||
<p>This link is valid for only one hour</p> | ||
<p>Please click on the link, or paste this into your browser to complete the process</p> | ||
${url} | ||
</div> | ||
<div> | ||
<h3 style="text-align: center">Thank you</h3> | ||
</div> | ||
</div> | ||
</div> | ||
</div>`, | ||
}; | ||
sgMail.send(msg); | ||
return true; | ||
}; | ||
|
||
export default sendEmail; |
Oops, something went wrong.