From 1a0491f2462d2c309bd8e310b22c11019a79ce1e Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Mon, 20 Mar 2017 16:02:14 +0000
Subject: [PATCH] #3527 fix - Added applications forms and metadata component
---
securis/src/main/webapp/src/app/user.service.ts | 35 +++++++----------------------------
1 files changed, 7 insertions(+), 28 deletions(-)
diff --git a/securis/src/main/webapp/src/app/user.service.ts b/securis/src/main/webapp/src/app/user.service.ts
index a0656a7..ee0c0b1 100644
--- a/securis/src/main/webapp/src/app/user.service.ts
+++ b/securis/src/main/webapp/src/app/user.service.ts
@@ -1,4 +1,5 @@
import { LocaleService } from './common/i18n';
+import { BasicService } from './common/utils';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
@@ -10,15 +11,15 @@
const SECURIS_TOKEN = "X-SECURIS-TOKEN";
@Injectable()
-export class UserService {
+export class UserService extends BasicService {
count : number = 0;
- constructor(private $L: LocaleService,
+ constructor($L: LocaleService,
private router: Router,
private store: LocalStorageService,
private http: Http) {
-
+ super($L);
}
public login(username: string, password: string) : Observable<string> {
@@ -28,7 +29,7 @@
let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
return this.http.post('user/login', params.toString(), options)
.map((resp) => this.mapLogin(resp))
- .catch((err) => this.handleError(err));
+ .catch((err) => super.processErrorResponse(err));
}
private mapLogin(res : Response) : string {
@@ -36,6 +37,7 @@
this.store.set('user_full_name', data.full_name);
this.store.set('username', data.username);
this.store.set('token', data.token);
+ console.log('New login token: ' + data.token);
return <string>data.token;
}
@@ -47,7 +49,7 @@
let option = new RequestOptions({ headers: new Headers({ 'X-SECURIS-TOKEN': token }) });
return this.http.get('check', option)
.map((resp) => this.mapCheck(resp))
- .catch((err) => this.handleError(err));
+ .catch((err) => super.processErrorResponse(err));
}
private mapCheck(res : Response) : boolean {
@@ -67,29 +69,6 @@
this.router.navigate(['public/login']);
}
-
- private handleError (error: Response | any) {
- // In a real world app, we might use a remote logging infrastructure
- let errMsg: string;
- if (error instanceof Response) {
- const err = JSON.stringify(error);
- errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
- } else {
- errMsg = error.message ? error.message : error.toString();
- }
-
- if (error.status === 403 /* forbidden */ || error.status === 401 /* unauthorized */) {
- errMsg = this.$L.get('Invalid credentials');
- } else if (error.status === 418 /* Teapot */) {
- errMsg = this.$L.get(error.headers.get('X-SECURIS-ERROR-MSG'));
- } else {
- console.error(error);
- errMsg = this.$L.get(`Unexpected error HTTP (${error.status}) accessing to server. Contact with the administrator.`);
- }
-
- console.error(errMsg);
- return Observable.throw(errMsg);
- }
}
--
Gitblit v1.3.2