From 41a2aee38cf812510010da09de9bae53590ec119 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 16:23:10 +0200 Subject: Follow the angular styleguide for the directories structure --- client/app/users/shared/token.model.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 client/app/users/shared/token.model.ts (limited to 'client/app/users/shared/token.model.ts') 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 @@ +export class Token { + access_token: string; + refresh_token: string; + token_type: string; + + static load(): Token { + return new Token({ + access_token: localStorage.getItem('access_token'), + refresh_token: localStorage.getItem('refresh_token'), + token_type: localStorage.getItem('token_type') + }); + } + + constructor (hash?: any) { + if (hash) { + this.access_token = hash.access_token; + this.refresh_token = hash.refresh_token; + if (hash.token_type === 'bearer') { + this.token_type = 'Bearer'; + } else { + this.token_type = hash.token_type; + } + } + } + + save():void { + localStorage.setItem('access_token', this.access_token); + localStorage.setItem('refresh_token', this.refresh_token); + localStorage.setItem('token_type', this.token_type); + } +} -- cgit v1.2.3