Skip to content

Commit f31efc9

Browse files
committed
feat(package): implemented the password strength api #191
1 parent 3968d12 commit f31efc9

File tree

9 files changed

+120
-16
lines changed

9 files changed

+120
-16
lines changed

demo/src/app/examples/examples-routing.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {MessagesComponent} from './messages/messages.component';
1010
import {GoBackURLComponent} from './go-back-url/go-back-url.component';
1111
import {RegistrationComponent} from './registration/registration.component';
1212
import {ResetPasswordComponent} from './reset-psasword/reset-password.component';
13+
import {PasswordStrengthComponent} from './password-strength/password-strength.component';
1314

1415
@NgModule({
1516
imports: [RouterModule.forChild([
@@ -23,6 +24,7 @@ import {ResetPasswordComponent} from './reset-psasword/reset-password.component'
2324
{path: 'tos', component: TosComponent},
2425
{path: 'tabIndex', component: TabIndexComponent},
2526
{path: 'gobackurl', component: GoBackURLComponent},
27+
{path: 'password-strength', component: PasswordStrengthComponent},
2628
])],
2729
exports: [RouterModule]
2830
})

demo/src/app/examples/examples.component.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ <h1>Examples</h1>
140140
<img fxHide.gt-lg src="assets/logo.svg" mat-card-md-image>
141141
</mat-card-title-group>
142142
</mat-card>
143+
144+
<mat-card matRipple routerLink="password-strength">
145+
<div fxHide
146+
fxShow.gt-lg
147+
fxLayout="column"
148+
fxLayoutAlign="center center">
149+
<img src="assets/logo.svg" mat-card-md-image>
150+
</div>
151+
<mat-card-title-group>
152+
<mat-card-title>Explore the password strength api</mat-card-title>
153+
<mat-card-subtitle>
154+
Configure the password strength in the register form on your own
155+
</mat-card-subtitle>
156+
<img fxHide.gt-lg src="assets/logo.svg" mat-card-md-image>
157+
</mat-card-title-group>
158+
</mat-card>
143159
</div>
144160
</div>
145161
</section>

demo/src/app/examples/examples.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {MessagesComponent} from './messages/messages.component';
1313
import { GoBackURLComponent } from './go-back-url/go-back-url.component';
1414
import { RegistrationComponent } from './registration/registration.component';
1515
import { ResetPasswordComponent } from './reset-psasword/reset-password.component';
16+
import {PasswordStrengthComponent} from './password-strength/password-strength.component';
1617

1718
@NgModule({
1819
imports: [
@@ -32,7 +33,8 @@ import { ResetPasswordComponent } from './reset-psasword/reset-password.componen
3233
MessagesComponent,
3334
GoBackURLComponent,
3435
RegistrationComponent,
35-
ResetPasswordComponent
36+
ResetPasswordComponent,
37+
PasswordStrengthComponent
3638
]
3739
})
3840
export class ExamplesModule {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<div class="jumbotron jumbotron-fluid">
2+
<div class="container">
3+
<h1>Password Strength API - Config</h1>
4+
</div>
5+
</div>
6+
7+
8+
<div class="container">
9+
10+
<div fxLayout="row wrap" fxLayout.xs="column" fxLayoutAlign="center">
11+
12+
<mat-card fxFlexAlign.gt-xs="center">
13+
<mat-card-subtitle>
14+
<div fxLayout="row" fxLayoutAlign="space-between">
15+
<pre><code [highlight]="example"></code></pre>
16+
<button mat-icon-button
17+
ngxClipboard
18+
[cbContent]="example"
19+
matTooltip="copy"
20+
(click)="showCopyMessage(example)">
21+
<mat-icon aria-label="copy content" class="mat-18">content_copy</mat-icon>
22+
</button>
23+
</div>
24+
</mat-card-subtitle>
25+
<mat-card-content>
26+
<ngx-auth-firebaseui tabIndex="1"
27+
[min]="8"
28+
[max]="15"
29+
[enableLengthRule]="true"
30+
[enableLowerCaseLetterRule]="true"
31+
[enableUpperCaseLetterRule]="true"
32+
[enableDigitRule]="true"
33+
[enableSpecialCharRule]="true"
34+
(onStrengthChanged)="onStrengthChanged($event)">
35+
</ngx-auth-firebaseui>
36+
</mat-card-content>
37+
</mat-card>
38+
</div>
39+
</div>
40+
41+
42+
43+
44+
45+

demo/src/app/examples/password-strength/password-strength.component.scss

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import {Component} from '@angular/core';
2+
import {MatSnackBar} from '@angular/material/snack-bar';
3+
import {ExampleBaseComponent} from '../example.abstract';
4+
5+
@Component({
6+
selector: 'app-password-strength',
7+
templateUrl: 'password-strength.component.html',
8+
styleUrls: ['password-strength.component.scss']
9+
})
10+
export class PasswordStrengthComponent extends ExampleBaseComponent {
11+
12+
example = `<ngx-auth-firebaseui tabIndex="1"
13+
[min]="8"
14+
[max]="15"
15+
[enableLengthRule]="true"
16+
[enableLowerCaseLetterRule]="true"
17+
[enableUpperCaseLetterRule]="true"
18+
[enableDigitRule]="true"
19+
[enableSpecialCharRule]="true"
20+
(onStrengthChanged)="onStrengthChanged($event)">
21+
</ngx-auth-firebaseui>`;
22+
23+
constructor(public snackBar: MatSnackBar) {
24+
super(snackBar);
25+
}
26+
27+
onStrengthChanged($event: number) {
28+
console.log('on strength changed: ', $event);
29+
}
30+
31+
}

src/module/components/ngx-auth-firebaseui/auth.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
<!--labels will work only with @angular/material@6.2.0 -->
9292
<mat-label>{{nameText}}</mat-label>
9393
<input matInput
94-
[minlength]="passwordStrength.min.toString()"
95-
[maxlength]="passwordStrength.max.toString()"
94+
[minlength]="2"
95+
[maxlength]="20"
9696
[formControl]="sigUpNameFormControl"
9797
required>
9898
<mat-icon matSuffix [color]="color">person</mat-icon>
@@ -140,18 +140,18 @@
140140
<mat-icon matSuffix [color]="color">lock</mat-icon>
141141

142142
<mat-hint align="end" aria-live="polite">
143-
{{signUpFormGroup.value.password?.length}} / {{ passwordStrength.max }}
143+
{{signUpFormGroup.value.password?.length}} / {{ max }}
144144
</mat-hint>
145145

146146
<mat-error *ngIf="sigUpPasswordFormControl.hasError('required')" class="cut-text">
147147
{{passwordErrorRequiredText}}
148148
</mat-error>
149149

150150
<mat-error *ngIf="sigUpPasswordFormControl.hasError('minlength')" class="cut-text">
151-
The password must be at least 6 characters long.
151+
The password must be at least {{min}} characters long.
152152
</mat-error>
153153
<mat-error *ngIf="sigUpPasswordFormControl.hasError('maxlength')" class="cut-text">
154-
The password can not be longer than 25 characters.
154+
The password can not be longer than {{max}} characters.
155155
</mat-error>
156156

157157
</mat-form-field>

src/module/components/ngx-auth-firebaseui/auth.component.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {HttpClientTestingModule} from '@angular/common/http/testing';
2121
import {AngularFireModule} from '@angular/fire';
2222
import {AngularFirestore} from '@angular/fire/firestore';
2323
import {AngularFireAuth} from '@angular/fire/auth';
24-
import {MatPasswordStrengthModule} from '@angular-material-extensions/password-strength';
24+
import {MatPasswordStrengthComponent, MatPasswordStrengthModule} from '@angular-material-extensions/password-strength';
2525
import {AuthComponent} from './auth.component';
2626
import {AuthProcessService} from '../../services/auth-process.service';
2727
import {FirestoreSyncService} from '../../services/firestore-sync.service';
@@ -81,6 +81,9 @@ describe('AuthComponent', function () {
8181
}).compileComponents().then(() => {
8282
fixture = TestBed.createComponent(AuthComponent);
8383
component = fixture.componentInstance;
84+
component.passwordStrength =
85+
TestBed.createComponent(MatPasswordStrengthComponent).componentInstance;
86+
8487
testBedService = TestBed.get(AuthProcessService);
8588

8689
// AuthService provided to the TestBed

src/module/components/ngx-auth-firebaseui/auth.component.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
AfterViewInit,
23
Component,
34
EventEmitter,
45
Inject,
@@ -37,8 +38,7 @@ export const PHONE_NUMBER_REGEX = new RegExp(/^\+(?:[0-9] ?){6,14}[0-9]$/);
3738
templateUrl: 'auth.component.html',
3839
styleUrls: ['auth.component.scss']
3940
})
40-
41-
export class AuthComponent implements OnInit, OnChanges, OnDestroy {
41+
export class AuthComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {
4242

4343
@ViewChild(MatTabGroup, {static: false}) matTabGroup: MatTabGroup;
4444
@ViewChild(MatPasswordStrengthComponent, {static: false}) passwordStrength: MatPasswordStrengthComponent;
@@ -55,6 +55,10 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
5555
@Input() messageOnAuthSuccess: string;
5656
@Input() messageOnAuthError: string;
5757

58+
@Output() onSuccess: any;
59+
@Output() onError: any;
60+
@Output() selectedTabChange: EventEmitter<MatTabChangeEvent> = new EventEmitter();
61+
5862
// Password strength api
5963
@Input() enableLengthRule = true;
6064
@Input() enableLowerCaseLetterRule = true;
@@ -100,10 +104,6 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
100104
@Input() registerButtonText = 'Register';
101105
@Input() guestButtonText = 'continue as guest';
102106

103-
@Output() onSuccess: any;
104-
@Output() onError: any;
105-
@Output() selectedTabChange: EventEmitter<MatTabChangeEvent> = new EventEmitter();
106-
107107
authProvider = AuthProvider;
108108
passwordResetWished: boolean;
109109

@@ -140,7 +140,6 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
140140

141141
public ngOnInit(): void {
142142
this.config = Object.assign(defaultAuthFirebaseUIConfig, this.config);
143-
this.onStrengthChanged = this.passwordStrength.onStrengthChanged;
144143

145144
if (isPlatformBrowser(this.platformId)) {
146145
this.onErrorSubscription = this.onError.subscribe(() => this.authenticationError = true);
@@ -152,6 +151,12 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
152151
this._initResetPasswordFormGroupBuilder();
153152
}
154153

154+
ngAfterViewInit(): void {
155+
this.passwordStrength.onStrengthChanged.subscribe((strength: number) => {
156+
this.onStrengthChanged.emit(strength);
157+
});
158+
}
159+
155160
ngOnChanges(changes: SimpleChanges): void {
156161
if (changes.messageOnAuthSuccess || changes.messageOnAuthError) {
157162
this.updateAuthSnackbarMessages();
@@ -258,8 +263,8 @@ export class AuthComponent implements OnInit, OnChanges, OnDestroy {
258263
password: this.sigUpPasswordFormControl = new FormControl('',
259264
[
260265
Validators.required,
261-
Validators.minLength(6),
262-
Validators.maxLength(25),
266+
Validators.minLength(this.min),
267+
Validators.maxLength(this.max),
263268
])
264269
});
265270
}

0 commit comments

Comments
 (0)