diff --git a/src/services/api/index.js b/src/services/api/index.js index 8fc08b3..4426397 100644 --- a/src/services/api/index.js +++ b/src/services/api/index.js @@ -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(); diff --git a/src/services/api/routes/index.js b/src/services/api/routes/index.js index 3ce4365..2f56b2e 100644 --- a/src/services/api/routes/index.js +++ b/src/services/api/routes/index.js @@ -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'), } }; \ No newline at end of file diff --git a/src/services/api/routes/v1/email.js b/src/services/api/routes/v1/email.js new file mode 100644 index 0000000..b3c9ce6 --- /dev/null +++ b/src/services/api/routes/v1/email.js @@ -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; \ No newline at end of file diff --git a/src/util.js b/src/util.js index c90400e..9518b9e 100644 --- a/src/util.js +++ b/src/util.js @@ -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,

Your Pretendo Network ID activation is almost complete. Please click the link below to confirm your e-mail address and complete the activation process.

https://account.pretendo.cc/account/email-confirmation?token=${pnid.get('identification.email_token')}

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.

<<Confirmation code: ${pnid.get('identification.email_code')}>>` + html: `Hello,

Your Pretendo Network ID activation is almost complete. Please click the link below to confirm your e-mail address and complete the activation process.

https://api.pretendo.cc/v1/email/verify?token=${pnid.get('identification.email_token')}

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.

<<Confirmation code: ${pnid.get('identification.email_code')}>>` }); }