Merge branch 'dev' of https://git.verdnatura.es/salix into dev
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
* @return {String} Token
|
||||
*/
|
||||
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
|
||||
*/
|
||||
sendWithTemplate: function(tplName, params, cb) {
|
||||
template.get(tplName, params, (error, result) => {
|
||||
template.get(tplName, params, false, (error, result) => {
|
||||
if (error)
|
||||
return cb(error);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var express = require('express');
|
||||
var router = new express.Router();
|
||||
var mail = require('../mail.js');
|
||||
var template = require('../template.js');
|
||||
|
||||
// Payment method changes
|
||||
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;
|
||||
|
|
|
@ -12,10 +12,10 @@ module.exports = {
|
|||
* @param {Object} params - Params
|
||||
* @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 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) => {
|
||||
if (error)
|
||||
|
@ -31,11 +31,11 @@ module.exports = {
|
|||
if (params.subject == undefined)
|
||||
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)
|
||||
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,17 +100,25 @@ module.exports = {
|
|||
* @param {String} body - template body
|
||||
* @param {Object} cb - Callback
|
||||
*/
|
||||
getAttachments: function(template, body, cb) {
|
||||
getAttachments: function(template, body, isPreview, cb) {
|
||||
let attachments = [];
|
||||
let tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig'));
|
||||
|
||||
// Template default attachments
|
||||
for (var i = 0; i < tplAttachments.length; i++) {
|
||||
let name = tplAttachments[i].replace('src="cid:', '').replace('"', '');
|
||||
let attachmentPath = path.join(__dirname, 'template/default/image', 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
|
||||
let attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json');
|
||||
|
@ -131,7 +139,7 @@ module.exports = {
|
|||
this.checkAttachments(attachments, error => {
|
||||
if (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 app = module.exports = express();
|
||||
var bodyParser = require('body-parser');
|
||||
|
@ -8,20 +5,21 @@ var settings = require('./application/settings.js');
|
|||
var mail = require('./application/mail.js');
|
||||
var database = require('./application/database.js');
|
||||
var auth = require('./application/auth.js');
|
||||
var path = require('path');
|
||||
|
||||
// Body parser middleware
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({extended: true}));
|
||||
|
||||
app.use('/static', express.static(path.join(__dirname, '/static')));
|
||||
|
||||
// Auth middleware
|
||||
var requestToken = function(request, response, next) {
|
||||
auth.init(request, response, next);
|
||||
};
|
||||
|
||||
app.use(requestToken);
|
||||
|
||||
// Load routes
|
||||
app.use('/', require('./application/router.js'));
|
||||
app.use('/', requestToken, require('./application/router.js'));
|
||||
|
||||
app.start = 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 |