7383-testToMaster #2445

Merged
alexm merged 233 commits from 7383-testToMaster into master 2024-05-14 05:44:13 +00:00
1 changed files with 22 additions and 11 deletions
Showing only changes of commit 329f875640 - Show all commits

View File

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