From 2762277c60db7df5ad3214b10a0dd93d4f2f1128 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 10 Mar 2017 08:53:44 +0000
Subject: [PATCH] #3527 feature - Added more features to angular2 version
---
securis/src/main/webapp/src/app/user.service.ts | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/securis/src/main/webapp/src/app/user.service.ts b/securis/src/main/webapp/src/app/user.service.ts
index 38d842d..13466d2 100644
--- a/securis/src/main/webapp/src/app/user.service.ts
+++ b/securis/src/main/webapp/src/app/user.service.ts
@@ -1,3 +1,4 @@
+import { LocaleService } from './common/i18n';
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Location } from '@angular/common';
@@ -11,7 +12,8 @@
@Injectable()
export class UserService {
- constructor(private router: Router,
+ constructor(private $L: LocaleService,
+ private router: Router,
private store: LocalStorageService,
private http: Http) {
@@ -22,14 +24,14 @@
params.append('username', username);
params.append('password', password);
let options = new RequestOptions({ headers: new Headers({ "Content-Type": "application/x-www-form-urlencoded" })});
- return this.http.post('user/login', params, options)
+ return this.http.post('user/login', params.toString(), options)
.map((res: Response) => {
let data = res.json();
this.store.set('username', username);
this.store.set('token', data.token);
return <string>data.token;
})
- .catch(this.handleError);
+ .catch((r) => this.handleError(r));
}
isLoggedIn() : Observable<Boolean> {
@@ -45,7 +47,7 @@
}
return body.valid;
})
- .catch(this.handleError)
+ .catch((r) => this.handleError(r))
.catch(() => Observable.of(false));
}
@@ -62,12 +64,21 @@
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
- const body = error.json() || '';
- const err = body.error || JSON.stringify(body);
+ 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