use ejs template
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2e36164a98
commit
acc88c8239
|
@ -1,7 +1,7 @@
|
||||||
/* eslint max-len: ["error", { "code": 150 }]*/
|
/* eslint max-len: ["error", { "code": 150 }]*/
|
||||||
const md5 = require('md5');
|
const md5 = require('md5');
|
||||||
const app = require('../../loopback/server/server.js');
|
const app = require('../../loopback/server/server.js');
|
||||||
const dataSources = require('../../print/config/print.json');
|
const dataSources = require('../../loopback/server/datasources.json');
|
||||||
const LoopBackContext = require('loopback-context');
|
const LoopBackContext = require('loopback-context');
|
||||||
const {Email} = require('vn-print');
|
const {Email} = require('vn-print');
|
||||||
|
|
||||||
|
@ -33,10 +33,35 @@ module.exports = Self => {
|
||||||
ctx.data.password = md5(ctx.data.password);
|
ctx.data.password = md5(ctx.data.password);
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.observe('before save', async(ctx, instance) => {
|
Self.afterRemote('create', async(ctx, instance) => {
|
||||||
console.log(instance);
|
console.log(instance);
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.instance.id;
|
||||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||||
|
const httpCtx = {req: loopBackContext.active};
|
||||||
|
const httpRequest = httpCtx.req.http.req;
|
||||||
|
const headers = httpRequest.headers;
|
||||||
|
const origin = headers.origin;
|
||||||
|
|
||||||
|
const user = await models.User.findById(userId);
|
||||||
|
console.log(user);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
type: 'email',
|
||||||
|
to: 'alexm@verdnatura.es',
|
||||||
|
from: dataSources.transports[0].host,
|
||||||
|
subject: 'Thanks for registering',
|
||||||
|
template: path.resolve(__dirname, '../../views/verify.ejs'),
|
||||||
|
redirect: `${origin}/!#/login/${instance.email}?emailConfirmed`,
|
||||||
|
host: 'verdnatura.es',
|
||||||
|
port: '1234',
|
||||||
|
protocol: 'https',
|
||||||
|
user: Self
|
||||||
|
};
|
||||||
|
|
||||||
|
await models.User.verify(options)
|
||||||
|
.then(res => console.log('> Verification email sent:', res));
|
||||||
|
/*
|
||||||
const changes = ctx.data || ctx.instance;
|
const changes = ctx.data || ctx.instance;
|
||||||
if (ctx.isNewInstance || !changes.email) return;
|
if (ctx.isNewInstance || !changes.email) return;
|
||||||
|
|
||||||
|
@ -86,7 +111,33 @@ module.exports = Self => {
|
||||||
const sendEmail = new Email('email-verify', params);
|
const sendEmail = new Email('email-verify', params);
|
||||||
|
|
||||||
// ctx.instance.verify(options);
|
// ctx.instance.verify(options);
|
||||||
sendEmail.send();
|
sendEmail.send();*/
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => {
|
||||||
|
console.log(instance);
|
||||||
|
const models = Self.app.models;
|
||||||
|
const userId = ctx.instance.id;
|
||||||
|
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||||
|
const httpCtx = {req: loopBackContext.active};
|
||||||
|
const httpRequest = httpCtx.req.http.req;
|
||||||
|
const headers = httpRequest.headers;
|
||||||
|
const origin = headers.origin;
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
type: 'email',
|
||||||
|
to: 'alexm@verdnatura.es',
|
||||||
|
from: dataSources.email.transports[0].host,
|
||||||
|
subject: 'Thanks for registering',
|
||||||
|
template: '../views/verify.ejs',
|
||||||
|
redirect: `${origin}/!#/login/${instance.email}?emailConfirmed`,
|
||||||
|
host: 'verdnatura.es',
|
||||||
|
port: '1234',
|
||||||
|
protocol: 'https',
|
||||||
|
user: Self
|
||||||
|
};
|
||||||
|
await models.user.verify(options)
|
||||||
|
.then(res => console.log('> Verification email sent:', res));
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.remoteMethod('getCurrentUserData', {
|
Self.remoteMethod('getCurrentUserData', {
|
||||||
|
@ -94,12 +145,12 @@ module.exports = Self => {
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'ctx',
|
arg: 'ctx',
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
http: {source: 'context'}
|
http: {source: 'context'}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -120,7 +171,7 @@ module.exports = Self => {
|
||||||
*
|
*
|
||||||
* @param {Integer} userId The user id
|
* @param {Integer} userId The user id
|
||||||
* @param {String} name The role name
|
* @param {String} name The role name
|
||||||
* @param {Object} options Options
|
* @param {object} options Options
|
||||||
* @return {Boolean} %true if user has the role, %false otherwise
|
* @return {Boolean} %true if user has the role, %false otherwise
|
||||||
*/
|
*/
|
||||||
Self.hasRole = async function(userId, name, options) {
|
Self.hasRole = async function(userId, name, options) {
|
||||||
|
@ -132,8 +183,8 @@ module.exports = Self => {
|
||||||
* Get all user roles.
|
* Get all user roles.
|
||||||
*
|
*
|
||||||
* @param {Integer} userId The user id
|
* @param {Integer} userId The user id
|
||||||
* @param {Object} options Options
|
* @param {object} options Options
|
||||||
* @return {Object} User role list
|
* @return {object} User role list
|
||||||
*/
|
*/
|
||||||
Self.getRoles = async(userId, options) => {
|
Self.getRoles = async(userId, options) => {
|
||||||
let result = await Self.rawSql(
|
let result = await Self.rawSql(
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<p>
|
||||||
|
Thanks for registering,
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Click <a href="<%=verifyHref%>">here</a> to confirm your email address.
|
||||||
|
</p>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<p>
|
||||||
|
Click <a href="<%=verifyHref%>">here</a> to confirm your email address.
|
||||||
|
</p>
|
|
@ -108,5 +108,20 @@
|
||||||
"allowedContentTypes": [
|
"allowedContentTypes": [
|
||||||
"application/x-7z-compressed"
|
"application/x-7z-compressed"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"name": "email",
|
||||||
|
"connector": "mail",
|
||||||
|
"transports": [{
|
||||||
|
"type": "smtp",
|
||||||
|
"host": "smtp.verdnatura.es",
|
||||||
|
"secure": true,
|
||||||
|
"port": 465,
|
||||||
|
"auth": {
|
||||||
|
"user": "nocontestar",
|
||||||
|
"pass": "",
|
||||||
|
"from": "nocontestar@verdnatura.es"
|
||||||
|
}
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue