Skip to content

Commit

Permalink
fix(app): put login() back in appRun
Browse files Browse the repository at this point in the history
- add isFetching check in UserService.login()
  • Loading branch information
Christine Yu committed Mar 31, 2016
1 parent 9b67d53 commit 699513e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/scripts/app.ts
Expand Up @@ -152,6 +152,8 @@ function appRun(gettextCatalog: any,
});
});

UserService.login();

ProjectsService.getProjects({
size: 100
})
Expand Down
49 changes: 27 additions & 22 deletions app/scripts/components/user/user.services.ts
Expand Up @@ -19,6 +19,7 @@ module ngApp.components.user.services {

class UserService implements IUserService {
currentUser: IUser;
isFetching: boolean = false;

/* @ngInject */
constructor(private AuthRestangular: restangular.IService,
Expand Down Expand Up @@ -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: "<span data-translate>Session expired or unauthorized.</span>",
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: "<span data-translate>Session expired or unauthorized.</span>",
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 {
Expand Down

0 comments on commit 699513e

Please sign in to comment.