4077-login_recover-password & account_verifyEmail #1063

Merged
alexm merged 52 commits from 4077-login_recover-password into dev 2022-11-28 11:34:03 +00:00
3 changed files with 36 additions and 8 deletions
Showing only changes of commit 41d2d14d39 - Show all commits

View File

@ -4,6 +4,8 @@ const app = require('../../loopback/server/server.js');
const dataSources = require('../../loopback/server/datasources.json'); const dataSources = require('../../loopback/server/datasources.json');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const path = require('path'); const path = require('path');
// const {Email} = require('vn-print');
// const qs = require('querystring');
module.exports = Self => { module.exports = Self => {
require('../methods/account/login')(Self); require('../methods/account/login')(Self);
@ -71,21 +73,50 @@ module.exports = Self => {
const origin = headers.origin; const origin = headers.origin;
const userId = ctx.instance.id; const userId = ctx.instance.id;
const user = await models.user.findById(userId);
/* //generate verification url
const generateVerificationToken = models.User.generateVerificationToken(user);
verifyOptions.verifyHref =
verifyOptions.protocol +
'://' +
verifyOptions.host +
displayPort +
urlPath +
'?' + qs.stringify({
uid: '' + verifyOptions.user[pkName],
redirect: verifyOptions.redirect,
});
verifyOptions.verifyHref +=
verifyOptions.verifyHref.indexOf('?') === -1 ? '?' : '&';
verifyOptions.verifyHref += 'token=' + user.verificationToken;
verifyOptions.verificationToken = user.verificationToken;
verifyOptions.text = verifyOptions.text || g.f('Please verify your email by opening ' +
'this link in a web browser:\n\t%s', verifyOptions.verifyHref);
verifyOptions.text = verifyOptions.text.replace(/\{href\}/g, verifyOptions.verifyHref);
const email = new Email('email-verify', {
recipient: instance.email,
lang: ctx.req.getLocale(),
url:
});
await email.send();
*/
const options = { const options = {
type: 'email', type: 'email',
to: instance.email, to: instance.email,
from: dataSources.email.transports[0].auth.from, from: 'test@test.es', // dataSources.email.transports[0].auth.from,
subject: 'Verify email', subject: 'Verify email',
template: path.resolve(__dirname, '../views/verify.ejs'), template: path.resolve(__dirname, '../views/verify.ejs'), // user.country.code = 'es' ? verifyES.ejs : verify.ejs
redirect: `${origin}/#!/account/${instance.id}/basic-data?emailConfirmed`, redirect: `${origin}/#!/account/${instance.id}/basic-data?emailConfirmed`,
host: origin.split(':')[1].split('/')[2], host: origin.split(':')[1].split('/')[2],
port: origin.split(':')[2], port: origin.split(':')[2],
protocol: origin.split(':')[0], protocol: origin.split(':')[0],
user: Self user: Self
}; };
console.log(options);
const user = await models.user.findById(userId); // await user.verify(options);
await user.verify(options);
}); });
Self.remoteMethod('getCurrentUserData', { Self.remoteMethod('getCurrentUserData', {

View File

@ -1,6 +1,3 @@
<p>
Thanks for registering,
</p>
<p> <p>
Click <a href="<%=verifyHref%>">here</a> to confirm your email address. Click <a href="<%=verifyHref%>">here</a> to confirm your email address.
</p> </p>

View File

@ -3,7 +3,7 @@ const emailHeader = new Component('email-header');
const emailFooter = new Component('email-footer'); const emailFooter = new Component('email-footer');
module.exports = { module.exports = {
name: 'recover-password', name: 'email-verify',
components: { components: {
'email-header': emailHeader.build(), 'email-header': emailHeader.build(),
'email-footer': emailFooter.build() 'email-footer': emailFooter.build()