Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Added confirm password
Browse files Browse the repository at this point in the history
  • Loading branch information
PurpleAxe committed Oct 26, 2023
1 parent 05882ee commit 8a1e298
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ <h3 class="ion-padding-start"><ion-text color="primary">Where Is the Power?</ion
<ion-text color="danger" *ngIf="signupForm.get('password')!.hasError('minlength')" class="ion-padding-start">
Password must be at least 8 characters
</ion-text>

<ion-item>
<ion-label position="floating">Confirm Password</ion-label>
<ion-input type="password" formControlName="confirmPassword" aria-label="Confrim Password"></ion-input>
</ion-item>
<ion-text color="danger" *ngIf="signupForm.get('confirmPassword')!.hasError('matchingErr')" class="ion-padding-start">
Passwords do not match
</ion-text>

<div class="ion-padding-top">
<ion-button expand="block" type="submit" data-cy="btn-confirm-signup" class="ion-margin-top ion-margin-start">Signup</ion-button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
import { ToastController } from '@ionic/angular';
import { RegisterUser } from '../../models/register-user';
Expand Down Expand Up @@ -27,16 +27,28 @@ export class SignupComponent implements OnInit {
lastName: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email]],
password: ['', [Validators.required, Validators.minLength(8)]],
confirmPassword: ['', Validators.required],
});


constructor(
private router: Router,
private formBuilder: FormBuilder,
private toastController: ToastController,
private authService: AuthService,
public modalController: ModalController,
private loadingController: LoadingController
) { }
) {
this.signupForm.addValidators(
this.comparePasswordValidator(
this.signupForm.controls['password'],
this.signupForm.controls['confirmPassword']
)
);
}





ngOnInit() { }
Expand All @@ -45,7 +57,24 @@ export class SignupComponent implements OnInit {
this.modalController.dismiss();
}


comparePasswordValidator(passwordOne: AbstractControl, passwordTwo: AbstractControl) {
return () => {
if (passwordOne.value !== passwordTwo.value) {
console.log("Passwords do not match")
return { match_error: 'matchingErr' };
}

return null;
};
}

signup() {
if(this.signupForm.value.password !== this.signupForm.value.confirmPassword) {
this.failToast('Passwords do not match');
return;
}

if (this.signupForm.valid) {
this.newUser.firstName = this.signupForm.value.firstName;
this.newUser.lastName = this.signupForm.value.lastName;
Expand Down

0 comments on commit 8a1e298

Please sign in to comment.