[CORD-989] Login errors
Change-Id: I781f3535110664d4b1de2659f6995102949ffb8c
diff --git a/src/app/core/login/login.html b/src/app/core/login/login.html
index 4fa78dc..12755ab 100644
--- a/src/app/core/login/login.html
+++ b/src/app/core/login/login.html
@@ -32,6 +32,7 @@
<input type="password" ng-model="password" title="Please enter your password" placeholder="******" required="" value="" name="password" id="password" class="form-control">
<!--<span class="help-block small">Your strong password</span>-->
</div>
+ <xos-alert config="{type: 'danger'}" show="vm.showErrorMsg">{{vm.errorMsg}}</xos-alert>
<div>
<button ng-click="vm.login(username, password)" class="btn btn-accent">Login</button>
<!--<a class="btn btn-default" href="register.html">Register</a>-->
diff --git a/src/app/core/login/login.ts b/src/app/core/login/login.ts
index 183980a..558fe37 100644
--- a/src/app/core/login/login.ts
+++ b/src/app/core/login/login.ts
@@ -8,7 +8,8 @@
static $inject = ['$log', 'AuthService', '$state', 'XosModelDiscoverer', 'StyleConfig'];
public loginStyle: any;
public img: string;
-
+ public showErrorMsg: boolean = false;
+ public errorMsg: string;
constructor(
private $log: ng.ILogService,
private authService: AuthService,
@@ -34,6 +35,7 @@
password: password
})
.then(res => {
+ this.showErrorMsg = false;
// after login set up models
return this.XosModelDiscoverer.discover();
})
@@ -41,7 +43,9 @@
this.$state.go('xos.dashboard');
})
.catch(e => {
- this.$log.error(e);
+ this.$log.error(`[XosLogin] Error during login.`);
+ this.errorMsg = `Something went wrong, please try again.`;
+ this.showErrorMsg = true;
});
}
diff --git a/src/app/datasources/rest/auth.rest.ts b/src/app/datasources/rest/auth.rest.ts
index edc2a65..81c4f7d 100644
--- a/src/app/datasources/rest/auth.rest.ts
+++ b/src/app/datasources/rest/auth.rest.ts
@@ -7,8 +7,6 @@
export interface IAuthResponseData extends IHttpPromiseCallbackArg<any> {
data: {
- // user: string;
- // xoscsrftoken: string;
sessionid: string;
};
}
@@ -39,10 +37,10 @@
const d = this.$q.defer();
this.$http.post(`${this.AppConfig.apiEndpoint}/utility/login`, data)
.then((res: IAuthResponseData) => {
- // this.$cookies.put('xoscsrftoken', res.data.xoscsrftoken, {path: '/'});
+ if (res.status >= 400) {
+ return d.reject(res.data);
+ }
this.$cookies.put('sessionid', res.data.sessionid, {path: '/'});
- // this.$cookies.put('xosuser', res.data.user, {path: '/'});
- // res.data.user = JSON.parse(res.data.user);
d.resolve(res.data);
})
.catch(e => {
diff --git a/src/interceptors.ts b/src/interceptors.ts
index 1ba6423..0a2bf74 100644
--- a/src/interceptors.ts
+++ b/src/interceptors.ts
@@ -1,19 +1,17 @@
/// <reference path="../typings/index.d.ts" />
-// TODO handle backend failure
-
export function interceptorConfig($httpProvider: angular.IHttpProvider, $resourceProvider: angular.resource.IResourceServiceProvider) {
$httpProvider.interceptors.push('UserStatusInterceptor');
$httpProvider.interceptors.push('CredentialsInterceptor');
$httpProvider.interceptors.push('NoHyperlinksInterceptor');
}
-export function userStatusInterceptor($state: angular.ui.IStateService, $cookies: ng.cookies.ICookiesService) {
-
+export function userStatusInterceptor($state: angular.ui.IStateService, $cookies: ng.cookies.ICookiesService, $q: ng.IQService) {
const checkLogin = (res) => {
if (res.status === 401 || res.status === -1) {
$cookies.remove('sessionid', {path: '/'});
$state.go('login');
+ return $q.reject(res);
}
return res;
};