mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 22:28:00 -05:00
Added email token confirmation
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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'),
|
||||
}
|
||||
};
|
||||
39
src/services/api/routes/v1/email.js
Normal file
39
src/services/api/routes/v1/email.js
Normal 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;
|
||||
@@ -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><<Confirmation code: ${pnid.get('identification.email_code')}>>`
|
||||
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><<Confirmation code: ${pnid.get('identification.email_code')}>>`
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user