-
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.
feature(verification): send verification email
[starts #167164980]
- Loading branch information
1 parent
1248009
commit 7e8e36c
Showing
16 changed files
with
343 additions
and
12 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
NODE_ENV= | ||
PORT= | ||
SECRET_KEY= | ||
VERIFY_SECRET = | ||
DATABASE_URL_DEV= | ||
DATABASE_URL_TEST= | ||
SERVER_URL= | ||
|
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
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,42 @@ | ||
import jwt from 'jsonwebtoken'; | ||
import pages from './emailMessages'; | ||
import mailer from '../services/sendMail'; | ||
import model from '../database/models'; | ||
|
||
const { User } = model; | ||
const { VerifyAccountEmailPage } = pages; | ||
|
||
/** | ||
* supplies subject and html page for email | ||
* @name msg | ||
* @param {Array} userName | ||
* @returns {object} subject and html page for email | ||
*/ | ||
|
||
const msg = (...userName) => ({ | ||
subject: 'Authors Haven - Verify Token', | ||
html: VerifyAccountEmailPage(userName), | ||
}); | ||
|
||
/** | ||
* verify user helper function | ||
* @name verifyUser | ||
* @param {object} info | ||
*/ | ||
|
||
const verifyUser = async (info) => { | ||
const { id, firstName, email } = info; | ||
const token = jwt.sign({ id }, process.env.ACCOUNT_VERIFICATION_SECRET, { expiresIn: '5h' }); | ||
await User.update({ | ||
verifiedToken: token | ||
}, { | ||
where: { | ||
id, | ||
} | ||
}); | ||
const url = `http://127.0.0.1:3000/api/v1/auth/verify/${token}/${id}`; | ||
const message = msg(firstName, url); | ||
mailer('williamsohworuka@gmail.com', email, message); | ||
}; | ||
|
||
export default verifyUser; |
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,9 +1,10 @@ | ||
import express from 'express'; | ||
import user from './user'; | ||
import auth from './auth'; | ||
import verifyEmail from './verifyEmail'; | ||
|
||
const router = express.Router(); | ||
|
||
router.use('/', user, auth); | ||
router.use('/', user, auth, verifyEmail); | ||
|
||
export default router; |
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,10 @@ | ||
import express from 'express'; | ||
import AuthController from '../controllers/AuthController'; | ||
|
||
const { updateStatus } = AuthController; | ||
const Router = express.Router(); | ||
|
||
const verifyBaseRoute = '/auth'; | ||
Router.get(`${verifyBaseRoute}/verify/:token/:id`, updateStatus); | ||
|
||
export default Router; |
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
Oops, something went wrong.