Merge branch 'dev' of https://git.verdnatura.es/salix into dev
|
@ -41,7 +41,7 @@ module.exports = {
|
||||||
* @return {String} Token
|
* @return {String} Token
|
||||||
*/
|
*/
|
||||||
getToken: function() {
|
getToken: function() {
|
||||||
return this.request.headers.authorization;
|
return this.request.headers.authorization || this.request.query.token;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -66,7 +66,7 @@ module.exports = {
|
||||||
* @param {Object} cb - Callback
|
* @param {Object} cb - Callback
|
||||||
*/
|
*/
|
||||||
sendWithTemplate: function(tplName, params, cb) {
|
sendWithTemplate: function(tplName, params, cb) {
|
||||||
template.get(tplName, params, (error, result) => {
|
template.get(tplName, params, false, (error, result) => {
|
||||||
if (error)
|
if (error)
|
||||||
return cb(error);
|
return cb(error);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = new express.Router();
|
var router = new express.Router();
|
||||||
var mail = require('../mail.js');
|
var mail = require('../mail.js');
|
||||||
|
var template = require('../template.js');
|
||||||
|
|
||||||
// Payment method changes
|
// Payment method changes
|
||||||
router.post('/payment-update/:clientId', function(request, response, next) {
|
router.post('/payment-update/:clientId', function(request, response, next) {
|
||||||
|
@ -22,4 +23,14 @@ router.post('/printer-setup/:clientId', function(request, response, next) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Printer setup preview
|
||||||
|
router.get('/printer-setup/:clientId', function(request, response, next) {
|
||||||
|
template.get('printer-setup', {recipient: request.params.clientId}, true, (error, result) => {
|
||||||
|
if (error)
|
||||||
|
return response.status(400).json({message: error.message});
|
||||||
|
|
||||||
|
response.send(result.body);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
@ -12,10 +12,10 @@ module.exports = {
|
||||||
* @param {Object} params - Params
|
* @param {Object} params - Params
|
||||||
* @param {Object} cb - Callback
|
* @param {Object} cb - Callback
|
||||||
*/
|
*/
|
||||||
get: function(template, params, cb) {
|
get: function(template, params, isPreview, cb) {
|
||||||
var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`);
|
var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`);
|
||||||
var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`);
|
var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`);
|
||||||
var stylePath = path.join(__dirname, 'template', `default`, `style.css`);
|
var stylePath = path.join(__dirname, '../static', 'css', 'style.css');
|
||||||
|
|
||||||
fs.stat(templatePath, (error, stat) => {
|
fs.stat(templatePath, (error, stat) => {
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -31,11 +31,11 @@ module.exports = {
|
||||||
if (params.subject == undefined)
|
if (params.subject == undefined)
|
||||||
params.subject = body.match(new RegExp('<title>(.*?)</title>', 'i'))[1];
|
params.subject = body.match(new RegExp('<title>(.*?)</title>', 'i'))[1];
|
||||||
|
|
||||||
this.getAttachments(template, body, (error, attachments) => {
|
this.getAttachments(template, body, isPreview, (error, result) => {
|
||||||
if (error)
|
if (error)
|
||||||
return cb(error);
|
return cb(error);
|
||||||
|
|
||||||
cb(null, {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments});
|
cb(null, {recipient: instance.recipient, subject: params.subject, body: result.body, attachments: result.attachments});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -100,18 +100,26 @@ module.exports = {
|
||||||
* @param {String} body - template body
|
* @param {String} body - template body
|
||||||
* @param {Object} cb - Callback
|
* @param {Object} cb - Callback
|
||||||
*/
|
*/
|
||||||
getAttachments: function(template, body, cb) {
|
getAttachments: function(template, body, isPreview, cb) {
|
||||||
let attachments = [];
|
let attachments = [];
|
||||||
let tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig'));
|
let tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig'));
|
||||||
|
|
||||||
// Template default attachments
|
// Template default attachments
|
||||||
for (var i = 0; i < tplAttachments.length; i++) {
|
for (var i = 0; i < tplAttachments.length; i++) {
|
||||||
let name = tplAttachments[i].replace('src="cid:', '').replace('"', '');
|
let name = tplAttachments[i].replace('src="cid:', '').replace('"', '');
|
||||||
let attachmentPath = path.join(__dirname, 'template/default/image', name);
|
|
||||||
|
|
||||||
attachments.push({filename: name, path: attachmentPath, cid: name});
|
if (isPreview) {
|
||||||
|
let attachmentPath = `/mailer/static/images/${name}`;
|
||||||
|
body = body.replace(tplAttachments[i], `src="${attachmentPath}"`);
|
||||||
|
} else {
|
||||||
|
let attachmentPath = path.join(__dirname, '../static', 'images', name);
|
||||||
|
attachments.push({filename: name, path: attachmentPath, cid: name});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPreview)
|
||||||
|
return cb(null, {body: body, attachments: attachments});
|
||||||
|
|
||||||
// Template attachment files
|
// Template attachment files
|
||||||
let attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json');
|
let attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json');
|
||||||
|
|
||||||
|
@ -131,7 +139,7 @@ module.exports = {
|
||||||
this.checkAttachments(attachments, error => {
|
this.checkAttachments(attachments, error => {
|
||||||
if (error)
|
if (error)
|
||||||
return cb(error);
|
return cb(error);
|
||||||
cb(null, attachments);
|
cb(null, {body: body, attachments: attachments});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/**
|
|
||||||
* Módulos necesarios
|
|
||||||
*/
|
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
var app = module.exports = express();
|
var app = module.exports = express();
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
|
@ -8,20 +5,21 @@ var settings = require('./application/settings.js');
|
||||||
var mail = require('./application/mail.js');
|
var mail = require('./application/mail.js');
|
||||||
var database = require('./application/database.js');
|
var database = require('./application/database.js');
|
||||||
var auth = require('./application/auth.js');
|
var auth = require('./application/auth.js');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
// Body parser middleware
|
// Body parser middleware
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(bodyParser.urlencoded({extended: true}));
|
app.use(bodyParser.urlencoded({extended: true}));
|
||||||
|
|
||||||
|
app.use('/static', express.static(path.join(__dirname, '/static')));
|
||||||
|
|
||||||
// Auth middleware
|
// Auth middleware
|
||||||
var requestToken = function(request, response, next) {
|
var requestToken = function(request, response, next) {
|
||||||
auth.init(request, response, next);
|
auth.init(request, response, next);
|
||||||
};
|
};
|
||||||
|
|
||||||
app.use(requestToken);
|
|
||||||
|
|
||||||
// Load routes
|
// Load routes
|
||||||
app.use('/', require('./application/router.js'));
|
app.use('/', requestToken, require('./application/router.js'));
|
||||||
|
|
||||||
app.start = function() {
|
app.start = function() {
|
||||||
var listener = app.listen(settings.app().port, function() {
|
var listener = app.listen(settings.app().port, function() {
|
||||||
|
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |