From 699513e54298bab3872d24f55964d148f31aaa26 Mon Sep 17 00:00:00 2001 From: Christine Yu Date: Thu, 31 Mar 2016 15:10:08 -0400 Subject: [PATCH] fix(app): put login() back in appRun - add isFetching check in UserService.login() --- app/scripts/app.ts | 2 + app/scripts/components/user/user.services.ts | 49 +++++++++++--------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/app/scripts/app.ts b/app/scripts/app.ts index f39b52591..9937f57e5 100755 --- a/app/scripts/app.ts +++ b/app/scripts/app.ts @@ -152,6 +152,8 @@ function appRun(gettextCatalog: any, }); }); + UserService.login(); + ProjectsService.getProjects({ size: 100 }) diff --git a/app/scripts/components/user/user.services.ts b/app/scripts/components/user/user.services.ts index 160303309..f9ef5fa4b 100755 --- a/app/scripts/components/user/user.services.ts +++ b/app/scripts/components/user/user.services.ts @@ -19,6 +19,7 @@ module ngApp.components.user.services { class UserService implements IUserService { currentUser: IUser; + isFetching: boolean = false; /* @ngInject */ constructor(private AuthRestangular: restangular.IService, @@ -48,29 +49,33 @@ module ngApp.components.user.services { } login(): void { - this.AuthRestangular.all("user") - .withHttpConfig({ - withCredentials: true - }) - .post({}, {}) - .then((data) => { - data.isFiltered = true; - this.setUser(data); - }, (response) => { - if(response.status === 401) { - if (this.currentUser) { - this.currentUser = undefined; - this.notify({ - message: "", - messageTemplate: "Session expired or unauthorized.", - container: "#notification", - classes: "alert-warning" - }); + if (!this.isFetching) { + this.isFetching = true; + this.AuthRestangular.all("user") + .withHttpConfig({ + withCredentials: true + }) + .post({}, {}) + .then((data) => { + data.isFiltered = true; + this.setUser(data); + }, (response) => { + if(response.status === 401) { + if (this.currentUser) { + this.currentUser = undefined; + this.notify({ + message: "", + messageTemplate: "Session expired or unauthorized.", + container: "#notification", + classes: "alert-warning" + }); + } + } else { + this.$log.error("Error logging in, response status " + response.status); } - } else { - this.$log.error("Error logging in, response status " + response.status); - } - }); + }) + .finally(() => this.isFetching = false); + } } getToken(): void {