Skip to content

Commit

Permalink
Fix bugs in Login and Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
iliasmentz committed Sep 30, 2018
1 parent 392a135 commit 5db6302
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/client/src/app/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions src/main/client/src/app/shared/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ export class UserService {
.toPromise() as Promise<Users>;
}

loginUser(username: string, password: string) {
let invalid = false;
this.authService.loginUser(username, password)
loginUser(username: string, password: string): Promise<boolean> {
return this.authService.loginUser(username, password)
.then(loginResponse => {

localStorage.setItem('access_token', loginResponse.access_token);
Expand All @@ -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) {
Expand Down
13 changes: 9 additions & 4 deletions src/main/client/src/app/welcome/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 5db6302

Please sign in to comment.