File

src/app/modules/recover-account/components/select-account-identifier/select-account-identifier.component.ts

Implements

OnInit

Metadata

Index

Properties
Methods

Constructor

constructor(activatedRoute: ActivatedRoute, resourceService: ResourceService, toasterService: ToasterService, router: Router, recoverAccountService: RecoverAccountService, configService: ConfigService)
Parameters :
Name Type Optional
activatedRoute ActivatedRoute No
resourceService ResourceService No
toasterService ToasterService No
router Router No
recoverAccountService RecoverAccountService No
configService ConfigService No

Methods

handleError
handleError(error)
Parameters :
Name Optional
error No
Returns : void
handleGenerateOtp
handleGenerateOtp(captchaResponse?)
Parameters :
Name Optional
captchaResponse Yes
Returns : void
initializeForm
initializeForm()
Returns : boolean
navigateToIdentifyAccount
navigateToIdentifyAccount()
Returns : void
navigateToNextStep
navigateToNextStep()
Returns : void
ngOnInit
ngOnInit()
Returns : void
resolved
resolved(captchaResponse: string)
Parameters :
Name Type Optional
captchaResponse string No
Returns : void
setSelectIdentifier
setSelectIdentifier(selectedAccountIdentifier)
Parameters :
Name Optional
selectedAccountIdentifier No
Returns : void
Private setTelemetryImpression
setTelemetryImpression()
Returns : void
submitSelection
submitSelection()
Returns : void
verifyState
verifyState()
Returns : boolean

Properties

Public activatedRoute
Type : ActivatedRoute
captchaRef
Type : RecaptchaComponent
Decorators :
@ViewChild('captchaRef')
Public configService
Type : ConfigService
disableFormSubmit
Default value : true
errorCount
Type : number
Default value : 0
googleCaptchaSiteKey
Type : string
isP2CaptchaEnabled
Type : any
Public recoverAccountService
Type : RecoverAccountService
Public resourceService
Type : ResourceService
Public router
Type : Router
selectedAccountIdentifier
Type : any
Default value : {}
telemetryCdata
Type : []
Default value : [{ id: 'user:account:recovery', type: 'Feature' }, { id: 'SB-13755', type: 'Task' }]
telemetryImpression
Type : IImpressionEventInput
Public toasterService
Type : ToasterService
validIdentifiers
Type : []
Default value : []
import { RecoverAccountService } from './../../services';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {ResourceService, ToasterService, ConfigService} from '@sunbird/shared';
import * as _ from 'lodash-es';
import { IImpressionEventInput } from '@sunbird/telemetry';
import { RecaptchaComponent } from 'ng-recaptcha';

@Component({
  templateUrl: './select-account-identifier.component.html',
  styleUrls: ['./select-account-identifier.component.scss']
})
export class SelectAccountIdentifierComponent implements OnInit {
  @ViewChild('captchaRef') captchaRef: RecaptchaComponent;
  selectedAccountIdentifier: any = {};
  validIdentifiers = [];
  errorCount = 0;
  disableFormSubmit = true;
  telemetryImpression: IImpressionEventInput;
  telemetryCdata = [{
    id: 'user:account:recovery',
    type: 'Feature'
  }, {
    id: 'SB-13755',
    type: 'Task'
  }];
  googleCaptchaSiteKey: string;
  isP2CaptchaEnabled: any;
  constructor(public activatedRoute: ActivatedRoute, public resourceService: ResourceService,
    public toasterService: ToasterService, public router: Router, public recoverAccountService: RecoverAccountService,
              public configService: ConfigService) {
  }

  ngOnInit() {
    if (this.verifyState()) {
      this.initializeForm();
    }
    this.setTelemetryImpression();
    try {
      this.googleCaptchaSiteKey = (<HTMLInputElement>document.getElementById('googleCaptchaSiteKey')).value;
    } catch (error) {
      this.googleCaptchaSiteKey = '';
    }
    this.isP2CaptchaEnabled = (<HTMLInputElement>document.getElementById('p2reCaptchaEnabled'))
      ? (<HTMLInputElement>document.getElementById('p2reCaptchaEnabled')).value : 'true';
  }
  setSelectIdentifier(selectedAccountIdentifier) {
    this.disableFormSubmit = false;
    this.selectedAccountIdentifier = selectedAccountIdentifier;
  }

  resolved(captchaResponse: string) {
    if (captchaResponse) {
      this.handleGenerateOtp(captchaResponse);
    }
  }

  submitSelection() {
    if (this.isP2CaptchaEnabled === 'true') {
      this.captchaRef.reset();
      this.captchaRef.execute();
    } else {
      this.handleGenerateOtp();
    }
  }

  handleGenerateOtp(captchaResponse?) {
    const request = {
      request: {
        type: this.selectedAccountIdentifier.type,
        key: this.selectedAccountIdentifier.value,
        userId: this.selectedAccountIdentifier.id,
        templateId: this.configService.constants.TEMPLATES.RESET_PASSWORD_TEMPLATE
      }
    };
    this.recoverAccountService.generateOTP(request, captchaResponse).subscribe(response => {
      this.navigateToNextStep();
    }, error => {
      this.handleError(error);
    });
  }
  verifyState() {
    if (!_.get(this.recoverAccountService, 'fuzzySearchResults.length')) {
      this.navigateToIdentifyAccount();
      return false;
    }
    return true;
  }
  navigateToNextStep() {
    this.recoverAccountService.selectedAccountIdentifier = this.selectedAccountIdentifier;
    this.router.navigate(['/recover/verify/account/identifier'], {
      queryParams: this.activatedRoute.snapshot.queryParams
    });
  }
  navigateToIdentifyAccount() {
    this.router.navigate(['/recover/identify/account'], {
      queryParams: this.activatedRoute.snapshot.queryParams
    });
  }
  handleError(error) {
    this.errorCount += 1;
    if (this.errorCount >= 2) {
      const reqQuery = this.activatedRoute.snapshot.queryParams;
      let resQuery: any = _.pick(reqQuery, ['client_id', 'redirect_uri', 'scope', 'state', 'response_type', 'version']);
      resQuery.error_message = 'Generate OTP failed. Please try again after some time';
      resQuery = Object.keys(resQuery).map(key =>
        encodeURIComponent(key) + '=' + encodeURIComponent(resQuery[key])).join('&');
      const redirect_uri = reqQuery.error_callback + '?' + resQuery;
      window.location.href = redirect_uri;
    } else {
      this.toasterService.error(this.resourceService.frmelmnts.lbl.generateOtpFailed);
    }
  }
  initializeForm() {
    _.forEach(this.recoverAccountService.fuzzySearchResults, element => {
      _.forIn(element, (value, key) => {
        if (['phone', 'email', 'prevUsedEmail', 'prevUsedPhone', 'recoveryEmail', 'recoveryPhone'].includes(key)) {
          if (value) {
            this.validIdentifiers.push({
              id: element.id,
              type: key,
              value: value
            });
          }
        }
      });
    });
    if (!this.validIdentifiers.length) {
      this.toasterService.error('No contact details found for linked account. Please try again');
      this.navigateToIdentifyAccount();
      return false;
    }
    return true;
  }
  private setTelemetryImpression() {
    this.telemetryImpression = {
      context: {
        env: this.activatedRoute.snapshot.data.telemetry.env,
        cdata: this.telemetryCdata
      },
      edata: {
        type: this.activatedRoute.snapshot.data.telemetry.type,
        pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
        uri: this.router.url
       // ,extra: { linkerAccount: this.validIdentifiers }
      }
    };
  }
}
<div class="sb-account-recover-page-section" [appTelemetryImpression]="telemetryImpression">
    <div class="mt-32 sb-account-recover-page-radio">
        <div class="text-center sb-account-recover-page-radio-label">{{resourceService?.frmelmnts?.lbl?.willsendOTP}}
        </div>
        <div class="text-center sb-account-recover-page-radio-label pb-16">
            {{resourceService?.frmelmnts?.lbl?.receiveOTP}}</div>
        <div class="mb-16 mt-24 text-left"
            *ngFor="let identifier of validIdentifiers">
            <mat-radio-button class="sb-radio-btn-primary" name="id" [value]="identifier.type" (change)="setSelectIdentifier(identifier)">
                {{identifier.value}}
              </mat-radio-button>
            <br>
        </div>
        <re-captcha *ngIf="isP2CaptchaEnabled === 'true'" #captchaRef="reCaptcha"
            (resolved)="$event && resolved($event)" siteKey="{{googleCaptchaSiteKey}}" size="invisible"></re-captcha>
        <a tabindex="0" (click)="captchaRef.reset()" id="resetGoogleCaptcha"></a>
        <button class="sb-btn sb-btn-normal width-100 mt-16 sb-btn-primary" tabindex="0" [disabled]="disableFormSubmit"
            appTelemetryInteract [telemetryInteractCdata]="telemetryCdata"
            [telemetryInteractEdata]="{id: 'generate-otp', type: 'click', pageid: 'select-identifier', extra: { form: selectedAccountIdentifier} }"
            tabindex="0" (click)="submitSelection()">{{resourceService?.frmelmnts?.lbl?.getOTP}}</button>
    </div>
</div>

./select-account-identifier.component.scss

@use "@project-sunbird/sb-styles/assets/mixins/mixins" as *;
@use './components/recover-account' as *;
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""