Compare commits
No commits in common. "5601ce5dac7ddd8f155961f4ea0d333a391bed04" and "b02e1f000ef61d4ba0c2156c66fccdb2d5582c31" have entirely different histories.
5601ce5dac
...
b02e1f000e
|
@ -1,8 +1,5 @@
|
|||
const tokenConfig = require('./token-config');
|
||||
|
||||
module.exports = async token => {
|
||||
const accessTokenConfig = await tokenConfig();
|
||||
|
||||
module.exports = async(token, accessTokenConfig) => {
|
||||
const now = new Date();
|
||||
const differenceMilliseconds = now - token.created;
|
||||
const differenceSeconds = Math.floor(differenceMilliseconds / 1000);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const tokenConfig = require('./token-config');
|
||||
const DEFAULT_COURTESY_TIME = 60;
|
||||
const handlePromiseLogout = (Self, {id}, courtesyTime = DEFAULT_COURTESY_TIME) => {
|
||||
const handlePromiseLogout = (Self, {id}, courtesyTime = 60) => {
|
||||
new Promise(res => {
|
||||
setTimeout(() => {
|
||||
res(Self.logout(id));
|
||||
|
@ -25,13 +23,14 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.renewToken = async function(ctx) {
|
||||
const {accessToken: token} = ctx.req;
|
||||
const models = Self.app.models;
|
||||
const token = ctx.req.accessToken;
|
||||
|
||||
// Check if current token is valid
|
||||
const isValid = await Self.validateToken(token);
|
||||
if (!isValid) throw new UserError(`The renew period has not been exceeded`, 'periodNotExceeded');
|
||||
|
||||
const {courtesyTime} = await tokenConfig();
|
||||
const fields = ['courtesyTime'];
|
||||
const {courtesyTime} = await models.AccessTokenConfig.findOne({fields});
|
||||
|
||||
// Schedule to remove current token
|
||||
handlePromiseLogout(Self, token, courtesyTime);
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
const DEFAULT_FIELDS = ['renewPeriod', 'courtesyTime'];
|
||||
const {models} = require('vn-loopback/server/server');
|
||||
let currentAccessTokenConfig = null;
|
||||
module.exports = async(fields = DEFAULT_FIELDS) => {
|
||||
if (currentAccessTokenConfig) return currentAccessTokenConfig;
|
||||
const accessTokenConfig = await models.AccessTokenConfig.findOne({fields});
|
||||
if (!accessTokenConfig) currentAccessTokenConfig = accessTokenConfig;
|
||||
return accessTokenConfig;
|
||||
};
|
|
@ -14,7 +14,9 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.validateToken = async function(token) {
|
||||
const isValid = await isTokenValid(token);
|
||||
const fields = ['renewPeriod', 'courtesyTime'];
|
||||
const accessTokenConfig = await Self.app.models.AccessTokenConfig.findOne({fields});
|
||||
const isValid = await isTokenValid(token, accessTokenConfig);
|
||||
return isValid;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
-- Auto-generated SQL script #202311061003
|
||||
UPDATE salix.accessTokenConfig
|
||||
SET courtesyTime=60
|
||||
WHERE id=1;
|
|
@ -2758,7 +2758,7 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk
|
|||
VALUES
|
||||
(1, 1);
|
||||
|
||||
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`, `maxTimeToBreak`, `maxWorkShortCycle`, `maxWorkLongCycle`)
|
||||
INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`, `maxTimeToBreak`, `maxWorkShortCycle`, `maxWorkLongCycle`)
|
||||
VALUES
|
||||
(1, 43200, 32400, 129600, 259200, 1080000, '', 'imap.verdnatura.es', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.00, 0.33, 40, '22:00:00', '06:00:00', 72000, 1200, 18000, 72000, 6, 13, 28800, 32400, 3600, 561600, 950400);
|
||||
|
||||
|
@ -2945,9 +2945,9 @@ INSERT INTO `vn`.`wagonTypeTray` (`id`, `typeFk`, `height`, `colorFk`)
|
|||
(2, 1, 50, 2),
|
||||
(3, 1, 0, 3);
|
||||
|
||||
INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `courtesyTime`, `renewInterval`)
|
||||
INSERT INTO `salix`.`accessTokenConfig` (`id`, `renewPeriod`, `renewInterval`)
|
||||
VALUES
|
||||
(1, 21600, 60, 300);
|
||||
(1, 21600, 300);
|
||||
|
||||
INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agencyFk`, `companyFk`)
|
||||
VALUES
|
||||
|
@ -2986,4 +2986,4 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`)
|
|||
VALUES
|
||||
(1, 'Error in VAT calculation'),
|
||||
(2, 'Error in sales details'),
|
||||
(3, 'Error in customer data');
|
||||
(3, 'Error in customer data');
|
|
@ -82,7 +82,7 @@ export default class Token {
|
|||
if (!data) return;
|
||||
this.renewPeriod = data.renewPeriod;
|
||||
this.stopRenewer();
|
||||
this.intervalId = setInterval(() => this.checkValidity(), data.renewInterval * 1000);
|
||||
this.inservalId = setInterval(() => this.checkValidity(), data.renewInterval * 1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ export default class Token {
|
|||
}
|
||||
|
||||
stopRenewer() {
|
||||
clearInterval(this.intervalId);
|
||||
clearInterval(this.inservalId);
|
||||
}
|
||||
}
|
||||
Token.$inject = ['vnInterceptor', '$http', '$rootScope'];
|
||||
|
|
Loading…
Reference in New Issue