aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/login
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/login')
-rw-r--r--client/src/app/login/login.component.html17
-rw-r--r--client/src/app/login/login.component.ts23
2 files changed, 26 insertions, 14 deletions
diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html
index 5848fcba3..636872942 100644
--- a/client/src/app/login/login.component.html
+++ b/client/src/app/login/login.component.html
@@ -1,16 +1,15 @@
1<h3>Login</h3> 1<h3>Login</h3>
2 2
3
4<div *ngIf="error" class="alert alert-danger">{{ error }}</div> 3<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
5 4
6<form role="form" (ngSubmit)="login(username.value, password.value)" #loginForm="ngForm"> 5<form role="form" (ngSubmit)="login()" [formGroup]="loginForm">
7 <div class="form-group"> 6 <div class="form-group">
8 <label for="username">Username</label> 7 <label for="username">Username</label>
9 <input 8 <input
10 type="text" class="form-control" name="username" id="username" placeholder="Username" required 9 type="text" class="form-control" name="username" id="username" placeholder="Username"
11 ngControl="username" #username="ngForm" 10 [(ngModel)]="username"
12 > 11 >
13 <div [hidden]="username.valid || username.pristine" class="alert alert-danger"> 12 <div [hidden]="loginForm.controls.username.valid || loginForm.controls.username.pristine" class="alert alert-danger">
14 Username is required 13 Username is required
15 </div> 14 </div>
16 </div> 15 </div>
@@ -18,13 +17,13 @@
18 <div class="form-group"> 17 <div class="form-group">
19 <label for="password">Password</label> 18 <label for="password">Password</label>
20 <input 19 <input
21 type="password" class="form-control" name="password" id="password" placeholder="Password" required 20 type="password" class="form-control" name="password" id="password" placeholder="Password"
22 ngControl="password" #password="ngForm" 21 [(ngModel)]="password"
23 > 22 >
24 <div [hidden]="password.valid || password.pristine" class="alert alert-danger"> 23 <div [hidden]="loginForm.controls.password.valid || loginForm.controls.password.pristine" class="alert alert-danger">
25 Password is required 24 Password is required
26 </div> 25 </div>
27 </div> 26 </div>
28 27
29 <input type="submit" value="Login" class="btn btn-default" [disabled]="!loginForm.form.valid"> 28 <input type="submit" value="Login" class="btn btn-default" [disabled]="!loginForm.valid">
30</form> 29</form>
diff --git a/client/src/app/login/login.component.ts b/client/src/app/login/login.component.ts
index ddd62462e..fe867b7b4 100644
--- a/client/src/app/login/login.component.ts
+++ b/client/src/app/login/login.component.ts
@@ -1,23 +1,36 @@
1import { Component } from '@angular/core'; 1import { Component, OnInit } from '@angular/core';
2import { Validators } from '@angular/common';
3import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
2import { Router } from '@angular/router'; 4import { Router } from '@angular/router';
3 5
4import { AuthService } from '../shared'; 6import { AuthService } from '../shared';
5 7
6@Component({ 8@Component({
7 selector: 'my-login', 9 selector: 'my-login',
8 template: require('./login.component.html') 10 template: require('./login.component.html'),
11 directives: [ REACTIVE_FORM_DIRECTIVES ]
9}) 12})
10 13
11export class LoginComponent { 14export class LoginComponent implements OnInit {
12 error: string = null; 15 error: string = null;
16 username = '';
17 password: '';
18 loginForm: FormGroup;
13 19
14 constructor( 20 constructor(
15 private authService: AuthService, 21 private authService: AuthService,
16 private router: Router 22 private router: Router
17 ) {} 23 ) {}
18 24
19 login(username: string, password: string) { 25 ngOnInit() {
20 this.authService.login(username, password).subscribe( 26 this.loginForm = new FormGroup({
27 username: new FormControl('', [ <any>Validators.required ]),
28 password: new FormControl('', [ <any>Validators.required ]),
29 });
30 }
31
32 login() {
33 this.authService.login(this.username, this.password).subscribe(
21 result => { 34 result => {
22 this.error = null; 35 this.error = null;
23 36