From 4fd8aa327004b27530fd96bdde5df60e6745a1f6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 17:49:18 +0200 Subject: Alphabetical --- client/app/users/shared/auth.service.ts | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'client/app/users/shared/auth.service.ts') diff --git a/client/app/users/shared/auth.service.ts b/client/app/users/shared/auth.service.ts index b1da94436..d63fe38f3 100644 --- a/client/app/users/shared/auth.service.ts +++ b/client/app/users/shared/auth.service.ts @@ -7,14 +7,14 @@ import { User } from './user.model'; @Injectable() export class AuthService { - private static BASE_LOGIN_URL = '/api/v1/users/token'; private static BASE_CLIENT_URL = '/api/v1/users/client'; + private static BASE_LOGIN_URL = '/api/v1/users/token'; loginChangedSource: Observable; - private loginChanged: Subject; private clientId: string; private clientSecret: string; + private loginChanged: Subject; constructor(private http: Http) { this.loginChanged = new Subject(); @@ -37,40 +37,14 @@ export class AuthService { ); } - 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 + getAuthRequestOptions(): RequestOptions { + return new RequestOptions({ headers: this.getRequestHeader() }); } getRequestHeader() { return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` }); } - getAuthRequestOptions(): RequestOptions { - return new RequestOptions({ headers: this.getRequestHeader() }); - } - getToken() { return localStorage.getItem('access_token'); } @@ -97,6 +71,32 @@ export class AuthService { } } + 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); } -- cgit v1.2.3