From 4a6995be18b15de1834a39c8921a0e4109671bb6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Jun 2016 22:08:03 +0200 Subject: First draft to use webpack instead of systemjs --- client/app/shared/users/auth-status.model.ts | 4 - client/app/shared/users/auth.service.ts | 108 --------------------------- client/app/shared/users/index.ts | 4 - client/app/shared/users/token.model.ts | 32 -------- client/app/shared/users/user.model.ts | 20 ----- 5 files changed, 168 deletions(-) delete mode 100644 client/app/shared/users/auth-status.model.ts delete mode 100644 client/app/shared/users/auth.service.ts delete mode 100644 client/app/shared/users/index.ts delete mode 100644 client/app/shared/users/token.model.ts delete mode 100644 client/app/shared/users/user.model.ts (limited to 'client/app/shared/users') diff --git a/client/app/shared/users/auth-status.model.ts b/client/app/shared/users/auth-status.model.ts deleted file mode 100644 index f646bd4cf..000000000 --- a/client/app/shared/users/auth-status.model.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum AuthStatus { - LoggedIn, - LoggedOut -} diff --git a/client/app/shared/users/auth.service.ts b/client/app/shared/users/auth.service.ts deleted file mode 100644 index d63fe38f3..000000000 --- a/client/app/shared/users/auth.service.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Headers, Http, RequestOptions, Response, URLSearchParams } from '@angular/http'; -import { Observable, Subject } from 'rxjs/Rx'; - -import { AuthStatus } from './auth-status.model'; -import { User } from './user.model'; - -@Injectable() -export class AuthService { - private static BASE_CLIENT_URL = '/api/v1/users/client'; - private static BASE_LOGIN_URL = '/api/v1/users/token'; - - loginChangedSource: Observable; - - private clientId: string; - private clientSecret: string; - private loginChanged: Subject; - - constructor(private http: Http) { - this.loginChanged = new Subject(); - this.loginChangedSource = this.loginChanged.asObservable(); - - // Fetch the client_id/client_secret - // FIXME: save in local storage? - this.http.get(AuthService.BASE_CLIENT_URL) - .map(res => res.json()) - .catch(this.handleError) - .subscribe( - result => { - this.clientId = result.client_id; - this.clientSecret = result.client_secret; - console.log('Client credentials loaded.'); - }, - error => { - alert(error); - } - ); - } - - getAuthRequestOptions(): RequestOptions { - return new RequestOptions({ headers: this.getRequestHeader() }); - } - - getRequestHeader() { - return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` }); - } - - getToken() { - return localStorage.getItem('access_token'); - } - - getTokenType() { - return localStorage.getItem('token_type'); - } - - getUser(): User { - if (this.isLoggedIn() === false) { - return null; - } - - const user = User.load(); - - return user; - } - - isLoggedIn() { - if (this.getToken()) { - return true; - } else { - return false; - } - } - - login(username: string, password: string) { - let body = new URLSearchParams(); - body.set('client_id', this.clientId); - body.set('client_secret', this.clientSecret); - body.set('response_type', 'code'); - body.set('grant_type', 'password'); - body.set('scope', 'upload'); - body.set('username', username); - body.set('password', password); - - let headers = new Headers(); - headers.append('Content-Type', 'application/x-www-form-urlencoded'); - - let options = { - headers: headers - }; - - return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options) - .map(res => res.json()) - .catch(this.handleError); - } - - logout() { - // TODO make HTTP request - } - - setStatus(status: AuthStatus) { - this.loginChanged.next(status); - } - - private handleError (error: Response) { - console.error(error); - return Observable.throw(error.json() || { error: 'Server error' }); - } -} diff --git a/client/app/shared/users/index.ts b/client/app/shared/users/index.ts deleted file mode 100644 index c6816b3c6..000000000 --- a/client/app/shared/users/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './auth-status.model'; -export * from './auth.service'; -export * from './token.model'; -export * from './user.model'; diff --git a/client/app/shared/users/token.model.ts b/client/app/shared/users/token.model.ts deleted file mode 100644 index 021c83fad..000000000 --- a/client/app/shared/users/token.model.ts +++ /dev/null @@ -1,32 +0,0 @@ -export class Token { - access_token: string; - refresh_token: string; - token_type: string; - - static load() { - 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() { - localStorage.setItem('access_token', this.access_token); - localStorage.setItem('refresh_token', this.refresh_token); - localStorage.setItem('token_type', this.token_type); - } -} diff --git a/client/app/shared/users/user.model.ts b/client/app/shared/users/user.model.ts deleted file mode 100644 index ca0a5f26c..000000000 --- a/client/app/shared/users/user.model.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Token } from './token.model'; - -export class User { - username: string; - token: Token; - - static load() { - return new User(localStorage.getItem('username'), Token.load()); - } - - constructor(username: string, hash_token: any) { - this.username = username; - this.token = new Token(hash_token); - } - - save() { - localStorage.setItem('username', this.username); - this.token.save(); - } -} -- cgit v1.2.3