File

src/app/components/forget-password/forget-password.component.ts

Implements

OnInit

Metadata

selector app-forget-password
styleUrls ./forget-password.component.scss
templateUrl ./forget-password.component.html

Index

Properties
Methods

Constructor

constructor(fb: FormBuilder, modalController: ModalController, swal: SwalService)
Parameters :
Name Type Optional
fb FormBuilder No
modalController ModalController No
swal SwalService No

Methods

checkFormControlIsValid
checkFormControlIsValid(control: string)
Parameters :
Name Type Optional
control string No
Returns : any
ngOnInit
ngOnInit()
Returns : void

Properties

dismissModal
Default value : () => {...}
emptyField
Default value : true
forgetPassword
Default value : () => {...}
ForgetPasswordForm
Type : FormGroup
getErrorMessage
Default value : () => {...}
invalidEmail
Type : any
Default value : true
import { SwalService } from './../../services/swal/swal.service';
import { ModalController } from '@ionic/angular';
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { auth } from 'firebase/app';
@Component({
  selector: 'app-forget-password',
  templateUrl: './forget-password.component.html',
  styleUrls: ['./forget-password.component.scss']
})
export class ForgetPasswordComponent implements OnInit {
  ForgetPasswordForm: FormGroup;
  invalidEmail: any = true;
  emptyField = true;

  constructor(
    private fb: FormBuilder,
    private modalController: ModalController,
    private swal: SwalService
  ) {}

  ngOnInit() {
    this.ForgetPasswordForm = this.fb.group({
      userEmail: ['', [Validators.required, Validators.email]]
    });
  }

  getErrorMessage = (controller: string) => {
    const formController = this.ForgetPasswordForm.controls[controller];
    return formController.hasError('required')
      ? 'You must enter a value'
      : formController.hasError('email')
      ? 'Not a valid email'
      : '';
  };

  checkFormControlIsValid(control: string) {
    return this.ForgetPasswordForm.controls[control].invalid;
  }

  forgetPassword = () => {
    const email = this.ForgetPasswordForm.controls['userEmail'].value;
    auth()
      .sendPasswordResetEmail(email)
      .then(() => {
        return this.modalController.dismiss();
      })
      .then(() => {
        this.swal.viewSuccessMessage(
          'Email sent',
          'Your Password reset email is sent successfully!, Please check your email'
        );
      })
      .catch(error => {
        if (error.code === 'auth/user-not-found') {
          this.swal.viewErrorMessage(
            'No such user',
            'Such user does not exist in our database please check your email again'
          );
        } else {
          this.swal.viewErrorMessage('Error', 'Error occured while sending the email!');
        }
        console.log('error occured while resetting the password');
        console.error(error);
      });
  };

  dismissModal = () => {
    this.modalController.dismiss();
  };
}
<ion-header>
  <ion-toolbar color="primary">
    <ion-title>Forget Password</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content class="ion-padding">
  <ion-text
    >If you have forgotten your password, you can submit a request and we will send you an email.
    You can add a new password using that</ion-text
  >
  <form
    [formGroup]="ForgetPasswordForm"
    style="width: 100%;height: 100%;display: flex;align-items: center"
  >
    <ion-grid>
      <ion-row align-items-center justify-content-center>
        <ion-col sizeLg="8" sizeXs="12">
          <mat-form-field class="formField" appearance="outline">
            <mat-hint>Place your University Email</mat-hint>
            <input matInput placeholder="Email" formControlName="userEmail" />
            <mat-error *ngIf="checkFormControlIsValid('userEmail')">{{
              getErrorMessage('userEmail')
            }}</mat-error>
          </mat-form-field>
        </ion-col>
      </ion-row>
    </ion-grid>
  </form>
</ion-content>

<ion-footer>
  <ion-button block (click)="forgetPassword()">Submit</ion-button>
  <ion-button block (click)="dismissModal()">Close</ion-button>
</ion-footer>

./forget-password.component.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""