-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into chore/164798013-auth-documentation
- Loading branch information
Showing
30 changed files
with
974 additions
and
253 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,44 @@ | ||
import notification from '../helpers/notifications'; | ||
import Authenticate from '../helpers/auth'; | ||
import model from '../models'; | ||
|
||
const { User } = model; | ||
|
||
const { hashPassword } = Authenticate; | ||
|
||
const ResetPasswordController = { | ||
async updatePassword(req, res) { | ||
try { | ||
const { email } = req.user; | ||
const hashedPassword = hashPassword(req.body.password); | ||
const newPassword = await User.update( | ||
{ password: hashedPassword }, | ||
{ | ||
where: { email }, | ||
returning: true, | ||
} | ||
); | ||
|
||
if (newPassword.length) { | ||
res.status(200).json({ | ||
status: 200, | ||
message: 'password reset successful', | ||
}); | ||
notification.passwordReset(email); | ||
} | ||
} catch (error) { | ||
return res.status(500).json({ | ||
message: error.message, | ||
}); | ||
} | ||
}, | ||
|
||
acceptRequest(req, res) { | ||
res | ||
.status(200) | ||
.redirect( | ||
`${req.protocol}://${req.get('host')}/api/v1/auth/reset/message` | ||
); | ||
}, | ||
}; | ||
export default ResetPasswordController; |
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,11 @@ | ||
import sendEmail from '../config/email'; | ||
|
||
const signupEmail = (email, link) => { | ||
const titile = 'Welcome to Authors Haven'; | ||
const body = `<p>click <a href=${link}>here</a> to confirm your email</p>`; | ||
sendEmail(email, titile, body); | ||
}; | ||
|
||
const emailSender = { signupEmail }; | ||
|
||
export default emailSender; |
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,22 @@ | ||
import sendEmail from '../config/email'; | ||
import template from './template'; | ||
|
||
const Notification = { | ||
forgetPassword(email, link) { | ||
const subject = 'Password Reset'; | ||
const message = template( | ||
`<p>You requested for a password reset</p> <p>follow this link to reset your password <a href=${link}>Reset my password</a></p><br><b>Please note that this link expires in 12hours and you can only use it once</b><p>If you didn't request for a password reset, ignore this email and nothing will happen</p>` | ||
); | ||
|
||
sendEmail(email, subject, message); | ||
}, | ||
|
||
passwordReset(email) { | ||
const subject = 'Password was changed'; | ||
const message = template('<p>Your password was changed successfuly</p>'); | ||
|
||
sendEmail(email, subject, message); | ||
}, | ||
}; | ||
|
||
export default Notification; |
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,26 @@ | ||
import models from '../models'; | ||
|
||
const { Keyword } = models; | ||
const serverError = 'Server error, please try again later'; | ||
|
||
const tagging = { | ||
/** | ||
* | ||
* @param {*} articleId | ||
* @param {*} tags | ||
* @returns {*} userId, articleId and keywords in an array. | ||
*/ | ||
async saveArticleTags(articleId, tags) { | ||
try { | ||
const Articletags = await Keyword.create({ | ||
article_id: articleId, | ||
keyword: tags, | ||
}); | ||
return Articletags; | ||
} catch (err) { | ||
return serverError; | ||
} | ||
}, | ||
}; | ||
|
||
export default tagging; |
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,43 @@ | ||
const template = ( | ||
title, | ||
body | ||
) => `<div style="font-family:-apple-system, '.SFNSText-Regular', 'Helvetica Neue', Roboto, 'Segoe UI', sans-serif; color: #666666; background:white; text-decoration: none; margin-bottom: 50px"> | ||
<table width="100%" cellpadding="0" cellspacing="0" border="0" summary=""> | ||
<tr align="center"> | ||
<td valign="top" style="width: 100%;"> | ||
<tabl cellspacing="0" cellpadding="0" border="0" summary=""> | ||
<tr align="center"> | ||
<td valign="middle" style="width: 100%;"> | ||
<a href="#"> | ||
<img style="width: 125px; cursor: pointer" src="https://res.cloudinary.com/dnch08bzc/image/upload/v1554130472/logo_transparent.png" alt="Authors Haven"> | ||
</a> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
<tr align="center"> | ||
<td valign="top" style="width: 80%;"> | ||
<table style="padding: 0px; border: 0; max-width: 520px; text-align: center;" width="100%" cellpadding="0" cellspacing="0" border="0" summary=""> | ||
<tr align="center" style="margin: 0px 10px;"> | ||
<td style="width: 100%; line-height: 24px; font-size: 11pt;"> | ||
<p>${title}</p> | ||
<p>${body}</p> | ||
</td> | ||
</tr> | ||
</table> | ||
<table style="border-collapse:collapse; max-width: 520px; text-align: center; margin-top: 30px" cellpadding="0" cellspacing="0" border="0" summary=""> | ||
<tr align="center"> | ||
<td style="width: 100%;"> | ||
<p style="line-height: 20px; font-size: 0.75rem; color: #b3b3b3;">Sent by | ||
<a href="#" style="color: #4a08ef;text-decoration: none;">Author's Haven</a> | ||
</p> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
</table> | ||
</div>`; | ||
|
||
export default template; |
Oops, something went wrong.