2019-01-23 12:11:44 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves and loads the token for the current logged in user.
|
|
|
|
*
|
|
|
|
* @property {String} token The current login token or %null
|
|
|
|
*/
|
|
|
|
export default class Token {
|
2019-01-25 11:04:35 +00:00
|
|
|
constructor() {
|
2019-01-23 12:11:44 +00:00
|
|
|
try {
|
|
|
|
this.token = sessionStorage.getItem('vnToken');
|
|
|
|
if (!this.token)
|
|
|
|
this.token = localStorage.getItem('vnToken');
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
set(value, remember) {
|
|
|
|
this.unset();
|
|
|
|
try {
|
|
|
|
if (remember)
|
|
|
|
localStorage.setItem('vnToken', value);
|
|
|
|
else
|
|
|
|
sessionStorage.setItem('vnToken', value);
|
2019-01-25 11:04:35 +00:00
|
|
|
} catch (e) {}
|
2019-01-23 12:11:44 +00:00
|
|
|
|
|
|
|
this.token = value;
|
|
|
|
}
|
|
|
|
unset() {
|
|
|
|
localStorage.removeItem('vnToken');
|
|
|
|
sessionStorage.removeItem('vnToken');
|
|
|
|
this.token = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModule.service('vnToken', Token);
|