7336_devToTest #2414

Merged
alexm merged 220 commits from 7336_devToTest into test 2024-05-07 06:26:53 +00:00
2 changed files with 24 additions and 13 deletions
Showing only changes of commit 27354e452f - Show all commits

View File

@ -12,8 +12,8 @@ module.exports = Self => {
http: { http: {
path: `/renewToken`, path: `/renewToken`,
verb: 'POST' verb: 'POST'
} },
}); accessScopes: ['DEFAULT', 'read:multimedia']});
Self.renewToken = async function(ctx) { Self.renewToken = async function(ctx) {
const {accessToken: token} = ctx.req; const {accessToken: token} = ctx.req;

View File

@ -1,5 +1,6 @@
import ngModule from '../module'; import ngModule from '../module';
const TOKEN_MULTIMEDIA = 'vnTokenMultimedia';
const TOKEN = 'vnToken';
/** /**
* Saves and loads the token for the current logged in user. * Saves and loads the token for the current logged in user.
* *
@ -58,8 +59,8 @@ export default class Token {
} }
getStorage(storage) { getStorage(storage) {
this.token = storage.getItem('vnToken'); this.token = storage.getItem(TOKEN);
this.tokenMultimedia = storage.getItem('vnTokenMultimedia'); this.tokenMultimedia = storage.getItem(TOKEN_MULTIMEDIA);
if (!this.token) return; if (!this.token) return;
const created = storage.getItem('vnTokenCreated'); const created = storage.getItem('vnTokenCreated');
this.created = created && new Date(created); this.created = created && new Date(created);
@ -67,15 +68,15 @@ export default class Token {
} }
setStorage(storage, token, tokenMultimedia, created, ttl) { setStorage(storage, token, tokenMultimedia, created, ttl) {
storage.setItem('vnTokenMultimedia', tokenMultimedia); storage.setItem(TOKEN_MULTIMEDIA, tokenMultimedia);
storage.setItem('vnToken', token); storage.setItem(TOKEN, token);
storage.setItem('vnTokenCreated', created.toJSON()); storage.setItem('vnTokenCreated', created.toJSON());
storage.setItem('vnTokenTtl', ttl); storage.setItem('vnTokenTtl', ttl);
} }
removeStorage(storage) { removeStorage(storage) {
storage.removeItem('vnToken'); storage.removeItem(TOKEN);
storage.removeItem('vnTokenMultimedia'); storage.removeItem(TOKEN_MULTIMEDIA);
storage.removeItem('vnTokenCreated'); storage.removeItem('vnTokenCreated');
storage.removeItem('vnTokenTtl'); storage.removeItem('vnTokenTtl');
} }
@ -96,9 +97,9 @@ export default class Token {
this.checking = true; this.checking = true;
const renewPeriod = Math.min(this.ttl, this.renewPeriod) * 1000; const renewPeriod = Math.min(this.ttl, this.renewPeriod) * 1000;
const maxDate = this.created.getTime() + renewPeriod; const maxDate = this.created.getTime() + renewPeriod;
const now = new Date(); const now = new Date().getTime();
if (now.getTime() <= maxDate) { if (now <= maxDate) {
this.checking = false; this.checking = false;
return; return;
} }
@ -106,7 +107,17 @@ export default class Token {
this.$http.post('VnUsers/renewToken') this.$http.post('VnUsers/renewToken')
.then(res => { .then(res => {
const token = res.data; const token = res.data;
this.set(token.id, now, token.ttl, this.remember); const tokenMultimedia =
localStorage.getItem(TOKEN_MULTIMEDIA)
?? sessionStorage.getItem(TOKEN_MULTIMEDIA);
return this.$http.post('VnUsers/renewToken', null, {
headers: {Authorization: tokenMultimedia}
})
.then(({data}) => {
const tokenMultimedia = data;
this.set(token.id, tokenMultimedia.id, new Date(), token.ttl, this.remember);
});
}) })
.finally(() => { .finally(() => {
this.checking = false; this.checking = false;
@ -119,4 +130,4 @@ export default class Token {
} }
Token.$inject = ['vnInterceptor', '$http', '$rootScope']; Token.$inject = ['vnInterceptor', '$http', '$rootScope'];
ngModule.service('vnToken', Token); ngModule.service(TOKEN, Token);