Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit ca2f339

Browse files
authored
fix(forms): Add required field validation to login and forgot password forms. (#40)
Fixes #24.
1 parent 7758ed2 commit ca2f339

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

src/authport/authport.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import { Account } from '../shared/account';
1616
<div class="panel-heading">
1717
<h4>
1818
<ul class="nav nav-pills">
19-
<li role="presentation" [ngClass]="{active:loginService.login || loginService.forgot}" id="login" (click)="showLogin()">
20-
<a>Sign In</a>
19+
<li role="presentation" [ngClass]="{active:loginService.login || loginService.forgot}" id="login">
20+
<a href="" (click)="showLogin(); false">Sign In</a>
2121
</li>
22-
<li role="presentation" [ngClass]="{active:loginService.register}" (click)="showRegister()" id="register" class="pull-right">
23-
<a>Register</a>
22+
<li role="presentation" [ngClass]="{active:loginService.register}" id="register" class="pull-right">
23+
<a href="" (click)="showRegister(); false">Register</a>
2424
</li>
2525
</ul>
2626
</h4>

src/forgot-password/forgot-password.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import { Stormpath, ForgotPasswordFormModel, StormpathErrorResponse } from '../s
1515
</div>
1616
<div class="row">
1717
<div class="col-xs-12">
18-
<form class="form-horizontal" *ngIf="!sent" (ngSubmit)="onSubmit()">
18+
<form class="form-horizontal" *ngIf="!sent" #form="ngForm" (ngSubmit)="onSubmit(form.value)">
1919
<div class="form-group">
2020
<label for="spEmail" class="col-sm-3 control-label">Email</label>
2121
<div class="col-sm-9">
2222
<input class="form-control" name="email" type="email" id="spEmail" [(ngModel)]="forgotPasswordFormModel.email"
23-
placeholder="Your Email Address" [disabled]="posting">
23+
placeholder="Your Email Address" [disabled]="posting" required>
2424
</div>
2525
</div>
2626
<div class="form-group">
@@ -70,7 +70,7 @@ export class ForgotPasswordComponent implements OnInit {
7070
(error: StormpathErrorResponse) => this.error = error.message);
7171
}
7272

73-
onSubmit(): void {
73+
onSubmit(form: any): void {
7474
this.send();
7575
}
7676
}

src/login/login.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,32 @@ import { Account } from '../shared/account';
55
import {
66
Stormpath, LoginFormModel, LoginService, StormpathErrorResponse
77
} from '../stormpath/stormpath.service';
8-
import { FormsModule } from '@angular/forms';
98

109
@Component({
1110
selector: 'login-form',
1211
template: `<template #defaultTemplate>
13-
<form class="form-horizontal">
12+
<form class="form-horizontal" #form="ngForm" (ngSubmit)="login(form.value)">
1413
<div class="form-group">
1514
<label for="loginField" class="col-sm-3 control-label">Email</label>
1615
<div class="col-sm-9">
17-
<input class="form-control" name="login" id="loginField" type="text" [(ngModel)]="loginFormModel.login">
16+
<input class="form-control" name="login" id="loginField" type="text" required [(ngModel)]="loginFormModel.login">
1817
</div>
1918
</div>
2019
<div class="form-group">
2120
<label for="passwordField" class="col-sm-3 control-label">Password</label>
2221
<div class="col-sm-9">
23-
<input class="form-control" name="password" id="passwordField" type="password" [(ngModel)]="loginFormModel.password">
22+
<input class="form-control" name="password" id="passwordField" type="password" required [(ngModel)]="loginFormModel.password">
2423
</div>
2524
</div>
2625
2726
<div class="form-group">
2827
<div class="col-xs-10 col-xs-offset-3 text-left">
29-
<a href="#" (click)="forgot()">&nbsp;Forgot Password?</a>
28+
<a href="#" (click)="forgot(); false">&nbsp;Forgot Password?</a>
3029
</div>
3130
</div>
3231
3332
<div *ngIf="error" class="alert alert-danger">{{error}}</div>
34-
<button (click)="login()" id="loginBtn" type="submit" class="btn btn-primary pull-right">Login</button>
33+
<button id="loginBtn" type="submit" class="btn btn-primary pull-right">Login</button>
3534
</form>
3635
</template>
3736
<template
@@ -68,7 +67,7 @@ export class LoginComponent implements OnInit {
6867
};
6968
}
7069

71-
login(): void {
70+
login(form: any): void {
7271
this.error = null;
7372
this.stormpath.login(this.loginFormModel)
7473
.subscribe(null, (error: StormpathErrorResponse) => {

test/forgot-password/forgot-password.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ describe('ForgotPasswordComponent', () => {
1515
let html: string = fixture.nativeElement.innerHTML.trim();
1616

1717
expect(html).toMatch(/<label class="(.*)control-label" for="spEmail">Email<\/label>/);
18-
expect(html).toMatch(/<input class="form-control(.*)" id="spEmail" name="email" placeholder="Your Email Address" type="email"/);
18+
expect(html).toMatch(/<input class="form-control(.*)" id="spEmail" name="email" placeholder="Your Email Address" required="" type="email"/);
1919
});
2020
});

test/login/login.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('LoginComponent', () => {
1717
expect(html).toMatch(/<label class="(.*)control-label" for="loginField">Email<\/label>/);
1818
expect(html).toMatch(/<label class="(.*)control-label" for="passwordField">Password<\/label>/);
1919

20-
expect(html).toMatch(/<input class="form-control(.*)" id="loginField" name="login" type="text"/);
21-
expect(html).toMatch(/<input class="form-control(.*)" id="passwordField" name="password" type="password"/);
20+
expect(html).toMatch(/<input class="form-control(.*)" id="loginField" name="login" required="" type="text"/);
21+
expect(html).toMatch(/<input class="form-control(.*)" id="passwordField" name="password" required="" type="password"/);
2222
});
2323

2424
});

0 commit comments

Comments
 (0)