try
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2022-10-21 13:46:53 +02:00
parent bcfbeb7032
commit 41d2d14d39
3 changed files with 36 additions and 8 deletions

View File

@ -4,6 +4,8 @@ const app = require('../../loopback/server/server.js');
const dataSources = require('../../loopback/server/datasources.json');
const LoopBackContext = require('loopback-context');
const path = require('path');
// const {Email} = require('vn-print');
// const qs = require('querystring');
module.exports = Self => {
require('../methods/account/login')(Self);
@ -71,21 +73,50 @@ module.exports = Self => {
const origin = headers.origin;
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 = {
type: 'email',
to: instance.email,
from: dataSources.email.transports[0].auth.from,
from: 'test@test.es', // dataSources.email.transports[0].auth.from,
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`,
host: origin.split(':')[1].split('/')[2],
port: origin.split(':')[2],
protocol: origin.split(':')[0],
user: Self
};
console.log(options);
const user = await models.user.findById(userId);
await user.verify(options);
// await user.verify(options);
});
Self.remoteMethod('getCurrentUserData', {

View File

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

View File

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