diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/src/app/login/login.component.html | 24 | ||||
-rw-r--r-- | client/src/app/login/login.component.ts | 8 |
2 files changed, 26 insertions, 6 deletions
diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html index 940694515..5848fcba3 100644 --- a/client/src/app/login/login.component.html +++ b/client/src/app/login/login.component.html | |||
@@ -1,14 +1,30 @@ | |||
1 | <h3>Login</h3> | 1 | <h3>Login</h3> |
2 | <form role="form" (submit)="login(username.value, password.value)"> | 2 | |
3 | |||
4 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
5 | |||
6 | <form role="form" (ngSubmit)="login(username.value, password.value)" #loginForm="ngForm"> | ||
3 | <div class="form-group"> | 7 | <div class="form-group"> |
4 | <label for="username">Username</label> | 8 | <label for="username">Username</label> |
5 | <input type="text" #username class="form-control" id="username" placeholder="Username"> | 9 | <input |
10 | type="text" class="form-control" name="username" id="username" placeholder="Username" required | ||
11 | ngControl="username" #username="ngForm" | ||
12 | > | ||
13 | <div [hidden]="username.valid || username.pristine" class="alert alert-danger"> | ||
14 | Username is required | ||
15 | </div> | ||
6 | </div> | 16 | </div> |
7 | 17 | ||
8 | <div class="form-group"> | 18 | <div class="form-group"> |
9 | <label for="password">Password</label> | 19 | <label for="password">Password</label> |
10 | <input type="password" #password class="form-control" id="password" placeholder="Password"> | 20 | <input |
21 | type="password" class="form-control" name="password" id="password" placeholder="Password" required | ||
22 | ngControl="password" #password="ngForm" | ||
23 | > | ||
24 | <div [hidden]="password.valid || password.pristine" class="alert alert-danger"> | ||
25 | Password is required | ||
26 | </div> | ||
11 | </div> | 27 | </div> |
12 | 28 | ||
13 | <input type="submit" value="Login" class="btn btn-default"> | 29 | <input type="submit" value="Login" class="btn btn-default" [disabled]="!loginForm.form.valid"> |
14 | </form> | 30 | </form> |
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts index 9d88536ca..768594ac4 100644 --- a/client/src/app/login/login.component.ts +++ b/client/src/app/login/login.component.ts | |||
@@ -9,6 +9,8 @@ import { AuthService, AuthStatus, User } from '../shared'; | |||
9 | }) | 9 | }) |
10 | 10 | ||
11 | export class LoginComponent { | 11 | export class LoginComponent { |
12 | error: string = null; | ||
13 | |||
12 | constructor( | 14 | constructor( |
13 | private authService: AuthService, | 15 | private authService: AuthService, |
14 | private router: Router | 16 | private router: Router |
@@ -17,6 +19,8 @@ export class LoginComponent { | |||
17 | login(username: string, password: string) { | 19 | login(username: string, password: string) { |
18 | this.authService.login(username, password).subscribe( | 20 | this.authService.login(username, password).subscribe( |
19 | result => { | 21 | result => { |
22 | this.error = null; | ||
23 | |||
20 | const user = new User(username, result); | 24 | const user = new User(username, result); |
21 | user.save(); | 25 | user.save(); |
22 | 26 | ||
@@ -26,9 +30,9 @@ export class LoginComponent { | |||
26 | }, | 30 | }, |
27 | error => { | 31 | error => { |
28 | if (error.error === 'invalid_grant') { | 32 | if (error.error === 'invalid_grant') { |
29 | alert('Credentials are invalid.'); | 33 | this.error = 'Credentials are invalid.'; |
30 | } else { | 34 | } else { |
31 | alert(`${error.error}: ${error.error_description}`); | 35 | this.error = `${error.error}: ${error.error_description}`; |
32 | } | 36 | } |
33 | } | 37 | } |
34 | ); | 38 | ); |