Mailer: Autentificación token por ruta. Fix creditClassification

This commit is contained in:
Joan Sanchez 2017-10-02 11:19:55 +02:00
parent 19e7e0d76b
commit aef9659798
6 changed files with 24 additions and 16 deletions

View File

@ -41,7 +41,7 @@ export default class Controller {
}
returnDialog(response) {
if (response === 'ACCEPT') {
this.$http.post(`/mailer/manuscript/${this.client.id}/payment-update`).then(
this.$http.post(`/mailer/manuscript/payment-update/${this.client.id}`).then(
() => this.vnApp.showMessage(this.translate.instant('Notification sent!'))
);
}

View File

@ -75,8 +75,8 @@ describe('Client', () => {
it('should request to send notification email', () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: '123'};
$httpBackend.when('POST', `/mailer/manuscript/${controller.client.id}/payment-update`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/${controller.client.id}/payment-update`);
$httpBackend.when('POST', `/mailer/manuscript/payment-update/${controller.client.id}`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/payment-update/${controller.client.id}`);
controller.returnDialog('ACCEPT');
$httpBackend.flush();
});

View File

@ -36,10 +36,13 @@ module.exports = function(Client) {
let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']};
app.models.CreditClassification.findOne(filter, function(err, data) {
app.models.CreditClassification.findOne(filter, function(error, data) {
if (error)
return;
let currentDate = new Date();
if (client.active && data.ended >= currentDate) {
if (data && client.active && (data.ended >= currentDate || data.ended == null)) {
let host = ctx.req.headers.host.split(':')[0];
var options = {
url: `http://${host}:5000/mailer/notification/client-deactivate/${client.id}`,

View File

@ -1,10 +1,16 @@
var express = require('express');
var router = new express.Router();
var mail = require('../mail.js');
var auth = require('../auth.js');
// Auth middleware
var requestToken = function(request, response, next) {
auth.init(request, response, next);
};
// Payment method changes
router.post('/:recipient/payment-update', function(request, response, next) {
mail.sendWithTemplate('payment-update', {recipient: request.params.recipient}, result => {
router.post('/payment-update/:clientId', requestToken, function(request, response, next) {
mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, result => {
return response.json(result);
});
});

View File

@ -3,6 +3,13 @@ var router = new express.Router();
var mail = require('../mail.js');
var database = require('../database.js');
var settings = require('../settings.js');
var auth = require('../auth.js');
// Auth middleware
var requestToken = function(request, response, next) {
auth.init(request, response, next);
};
// Single user notification
/* router.post('/:recipient/noticeUserSend', function(request, response) {
var params = {
@ -64,7 +71,7 @@ var settings = require('../settings.js');
}); */
// Send notification to alias solunion on client deactivate
router.post('/client-deactivate/:clientId', function(request, response) {
router.post('/client-deactivate/:clientId', requestToken, function(request, response) {
var params = {
alias: 'solunion',
code: 'clientDeactivate',

View File

@ -7,19 +7,11 @@ var bodyParser = require('body-parser');
var settings = require('./application/settings.js');
var mail = require('./application/mail.js');
var database = require('./application/database.js');
var auth = require('./application/auth.js');
// Body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// Auth middleware
var requestToken = function(request, response, next) {
auth.init(request, response, next);
};
app.use(requestToken);
// Load routes
app.use('/', require('./application/router.js'));