Added slices
Change-Id: I9dfaa9348fa82da844a04c0c2a58ce07e9fa3a28
diff --git a/src/app/services/rest/auth.service.ts b/src/app/services/rest/auth.service.ts
index b5b00fb..978825f 100644
--- a/src/app/services/rest/auth.service.ts
+++ b/src/app/services/rest/auth.service.ts
@@ -2,7 +2,7 @@
// Imports
import {AppConfig} from '../../config/app.config';
-import {Injectable} from '@angular/core';
+import {Injectable} from '@angular/core';
import {Http, Response, Headers} from '@angular/http';
import {Observable} from 'rxjs/Rx';
import {IAuthRequest, IAuthResponse} from '../../interfaces/auth.interface';
@@ -28,13 +28,35 @@
}
// get auth info to authenticate API
- getUserHeaders(): Headers{
+ getUserHeaders(): Headers {
const headers = new Headers();
headers.append('x-csrftoken', this.cookieService.get('xoscsrftoken'));
headers.append('x-sessionid', this.cookieService.get('xossessionid'));
return headers;
}
+ // log the user in
+ login(auth: IAuthRequest): Observable<IAuthResponse> {
+ return this.http.post(`${AppConfig.apiEndpoint}/utility/login/`, auth)
+ .map((res: Response) => res.json())
+ .map((auth: IAuthResponse) => {
+ this.storeAuth(auth);
+ auth.user = JSON.parse(auth.user);
+ return auth;
+ })
+ .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
+ }
+
+ // logout the user
+ logout(): Observable<any> {
+ return this.http.post(`${AppConfig.apiEndpoint}/utility/logout/`, {xossessionid: this.xosSessionId})
+ .map((res: Response) => {
+ this.removeAuth();
+ return res.text();
+ })
+ .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
+ }
+
// save cookies
private storeAuth(auth: IAuthResponse): void {
this.cookieService.put('xoscsrftoken', auth.xoscsrftoken);
@@ -46,27 +68,5 @@
this.cookieService.remove('xoscsrftoken');
this.cookieService.remove('xossessionid');
}
-
- // log the user in
- login(auth: IAuthRequest): Observable<IAuthResponse> {
- return this.http.post(`${AppConfig.apiEndpoint}/utility/login/`, auth)
- .map((res: Response) => res.json())
- .map((auth: IAuthResponse) => {
- this.storeAuth(auth);
- auth.user = JSON.parse(auth.user);
- return auth;
- })
- .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
- }
-
- // logout the user
- logout(): Observable<any> {
- return this.http.post(`${AppConfig.apiEndpoint}/utility/logout/`, {xossessionid: this.xosSessionId})
- .map((res: Response) => {
- this.removeAuth();
- return res.text();
- })
- .catch((error: any) => Observable.throw(error.json().error || 'Server error'));
- }
}