diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-05-27 16:23:10 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-05-27 16:23:10 +0200 |
commit | 41a2aee38cf812510010da09de9bae53590ec119 (patch) | |
tree | 79d55d6ae0ef6f66ccb88890cf1ef1946dc65fb4 /client/app/users/shared/token.model.ts | |
parent | 157cb9c9713e08ff70078660a32dd77ecb87eabc (diff) | |
download | PeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.gz PeerTube-41a2aee38cf812510010da09de9bae53590ec119.tar.zst PeerTube-41a2aee38cf812510010da09de9bae53590ec119.zip |
Follow the angular styleguide for the directories structure
Diffstat (limited to 'client/app/users/shared/token.model.ts')
-rw-r--r-- | client/app/users/shared/token.model.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/client/app/users/shared/token.model.ts b/client/app/users/shared/token.model.ts new file mode 100644 index 000000000..b7872e74a --- /dev/null +++ b/client/app/users/shared/token.model.ts | |||
@@ -0,0 +1,31 @@ | |||
1 | export class Token { | ||
2 | access_token: string; | ||
3 | refresh_token: string; | ||
4 | token_type: string; | ||
5 | |||
6 | static load(): Token { | ||
7 | return new Token({ | ||
8 | access_token: localStorage.getItem('access_token'), | ||
9 | refresh_token: localStorage.getItem('refresh_token'), | ||
10 | token_type: localStorage.getItem('token_type') | ||
11 | }); | ||
12 | } | ||
13 | |||
14 | constructor (hash?: any) { | ||
15 | if (hash) { | ||
16 | this.access_token = hash.access_token; | ||
17 | this.refresh_token = hash.refresh_token; | ||
18 | if (hash.token_type === 'bearer') { | ||
19 | this.token_type = 'Bearer'; | ||
20 | } else { | ||
21 | this.token_type = hash.token_type; | ||
22 | } | ||
23 | } | ||
24 | } | ||
25 | |||
26 | save():void { | ||
27 | localStorage.setItem('access_token', this.access_token); | ||
28 | localStorage.setItem('refresh_token', this.refresh_token); | ||
29 | localStorage.setItem('token_type', this.token_type); | ||
30 | } | ||
31 | } | ||