Added email token confirmation

This commit is contained in:
Jonathan Barrow
2022-10-01 01:15:46 -04:00
parent e4edb5e0e5
commit f701647747
4 changed files with 49 additions and 7 deletions

View File

@@ -17,10 +17,12 @@ api.options('*', cors());
// Setup routes
logger.info('[USER API] Applying imported routes');
api.use('/v1/register', routes.V1.REGISTER);
api.use('/v1/login', routes.V1.LOGIN);
api.use('/v1/user', routes.V1.USER);
api.use('/v1/connections', routes.V1.CONNECTIONS);
api.use('/v1/email', routes.V1.EMAIL);
api.use('/v1/login', routes.V1.LOGIN);
api.use('/v1/register', routes.V1.REGISTER);
api.use('/v1/user', routes.V1.USER);
// Main router for endpoints
const router = express.Router();

View File

@@ -1,8 +1,9 @@
module.exports = {
V1: {
REGISTER: require('./v1/register'),
LOGIN: require('./v1/login'),
USER: require('./v1/user'),
CONNECTIONS: require('./v1/connections'),
EMAIL: require('./v1/email'),
LOGIN: require('./v1/login'),
REGISTER: require('./v1/register'),
USER: require('./v1/user'),
}
};

View File

@@ -0,0 +1,39 @@
const router = require('express').Router();
const moment = require('moment');
const { PNID } = require('../../../../models/pnid');
router.get('/verify', async (request, response) => {
const { token } = request.query;
if (!token || token.trim() == '') {
return response.status(400).json({
app: 'api',
status: 400,
error: 'Missing email token'
});
}
const pnid = await PNID.findOne({
'identification.email_token': token
});
if (!pnid) {
return response.status(400).json({
app: 'api',
status: 400,
error: 'Invalid email token'
});
}
const validatedDate = moment().format('YYYY-MM-DDTHH:MM:SS');
pnid.set('email.reachable', true);
pnid.set('email.validated', true);
pnid.set('email.validated_date', validatedDate);
await pnid.save();
response.status(200).send('Email validated. You may close this window');
});
module.exports = router;

View File

@@ -233,7 +233,7 @@ async function sendConfirmationEmail(pnid) {
await mailer.sendMail({
to: pnid.get('email.address'),
subject: '[Pretendo Network] Please confirm your e-mail address',
html: `Hello,<br><br>Your Pretendo Network ID activation is almost complete. Please click the link below to confirm your e-mail address and complete the activation process.<br><br>https://account.pretendo.cc/account/email-confirmation?token=${pnid.get('identification.email_token')}<br><br>If you are unable to connect to the above URL, please enter the following confirmation code on the device to which your Prentendo Network ID is linked.<br><br>&lt;&lt;Confirmation code: ${pnid.get('identification.email_code')}&gt;&gt;`
html: `Hello,<br><br>Your Pretendo Network ID activation is almost complete. Please click the link below to confirm your e-mail address and complete the activation process.<br><br>https://api.pretendo.cc/v1/email/verify?token=${pnid.get('identification.email_token')}<br><br>If you are unable to connect to the above URL, please enter the following confirmation code on the device to which your Prentendo Network ID is linked.<br><br>&lt;&lt;Confirmation code: ${pnid.get('identification.email_code')}&gt;&gt;`
});
}