diff --git a/src/main/client/src/app/settings/settings.component.ts b/src/main/client/src/app/settings/settings.component.ts index 40120b3..93c10a1 100644 --- a/src/main/client/src/app/settings/settings.component.ts +++ b/src/main/client/src/app/settings/settings.component.ts @@ -48,7 +48,7 @@ export class SettingsComponent implements OnInit { onChangePassword(passwordForm: FormGroup) { let password = new PasswordChange(passwordForm); - if (passwordForm.valid || password.newPassword !== password.newPasswordRepeat) { + if (!passwordForm.valid || password.newPassword !== password.newPasswordRepeat) { this.passwordMismatch = true; return; } @@ -61,7 +61,7 @@ export class SettingsComponent implements OnInit { onChangeEmail(emailForm: FormGroup) { let email = new EmailChange(emailForm); - if (emailForm.valid) { + if (!emailForm.valid) { this.emailInvalid = true; return; } diff --git a/src/main/client/src/app/shared/user/user.service.ts b/src/main/client/src/app/shared/user/user.service.ts index ebbcbfa..806026e 100644 --- a/src/main/client/src/app/shared/user/user.service.ts +++ b/src/main/client/src/app/shared/user/user.service.ts @@ -34,9 +34,8 @@ export class UserService { .toPromise() as Promise; } - loginUser(username: string, password: string) { - let invalid = false; - this.authService.loginUser(username, password) + loginUser(username: string, password: string): Promise { + return this.authService.loginUser(username, password) .then(loginResponse => { localStorage.setItem('access_token', loginResponse.access_token); @@ -49,12 +48,11 @@ export class UserService { .catch( err => { console.log("can't get the user: " + err); }); - invalid = false; + return false; }) .catch(error => { - invalid = true; + return true; }); - return invalid; } updateUser(userRequest: UserDto) { diff --git a/src/main/client/src/app/welcome/login/login.component.ts b/src/main/client/src/app/welcome/login/login.component.ts index 72e6678..2fd0a8a 100644 --- a/src/main/client/src/app/welcome/login/login.component.ts +++ b/src/main/client/src/app/welcome/login/login.component.ts @@ -29,10 +29,15 @@ export class LoginComponent implements OnInit { if (this.loginForm.valid) { const username = this.loginForm.get('username').value; const password = this.loginForm.get('password').value; - invalid = this.userService.loginUser(username, password); - } - if (!this.loginForm.valid || invalid) { - this.showError = true + this.userService.loginUser(username, password) + .then(invalidRequest => { + invalid = invalidRequest; + if (invalid) { + this.showError = true; + } + }); + } else { + this.showError = true; } }