File

src/app/modules/recover-account/components/identify-account/identify-account.component.ts

Metadata

styleUrls identify-account.component.scss
templateUrl identify-account.component.html

Constructor

constructor(activatedRoute: ActivatedRoute, resourceService: any, formBuilder: UntypedFormBuilder, toasterService: any, router: Router, recoverAccountService: RecoverAccountService, recaptchaService: any, telemetryService: any)

Methods

initializeForm
initializeForm()
Returns: void
handleNext
handleNext(captchaResponse: string)
Returns: void
initiateFuzzyUserSearch
initiateFuzzyUserSearch()
Returns: void
resetGoogleCaptcha
resetGoogleCaptcha()
Returns: void
navigateToNextStep
navigateToNextStep(response: any)
Returns: void
handleError
handleError(error: any)
Returns: void
Private setTelemetryImpression
setTelemetryImpression()
Returns: void

Properties

activatedRoute
activatedRoute: ActivatedRoute
captchaRef
captchaRef: RecaptchaComponent
disableFormSubmit
disableFormSubmit: boolean
Default value: true
errorCount
errorCount: number
Default value: 0
form
form: any
formBuilder
formBuilder: UntypedFormBuilder
googleCaptchaSiteKey
googleCaptchaSiteKey: string
identiferStatus
identiferStatus: string
nameNotExist
nameNotExist: boolean
Default value: false
recaptchaService
recaptchaService: any
recoverAccountService
recoverAccountService: RecoverAccountService
resourceService
resourceService: any
router
router: Router
telemetryCdata
telemetryCdata: { id: string; type: string; }[]
telemetryImpression
telemetryImpression: any
telemetryService
telemetryService: any
toasterService
toasterService: any
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { RecoverAccountService } from './../../services';
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {RecaptchaService, ResourceService, ToasterService} from '@sunbird/shared';
import {TelemetryService} from '@sunbird/telemetry';
import { UntypedFormBuilder, Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
import * as _ from 'lodash-es';
import { IImpressionEventInput, IEndEventInput, IStartEventInput, IInteractEventObject, IInteractEventEdata } from '@sunbird/telemetry';
import { RecaptchaComponent } from 'ng-recaptcha';

@Component({
  templateUrl: './identify-account.component.html',
  styleUrls: ['./identify-account.component.scss']
})
export class IdentifyAccountComponent implements OnInit {

  disableFormSubmit = true;
  @ViewChild('captchaRef') captchaRef: RecaptchaComponent;
  googleCaptchaSiteKey: string;
  nameNotExist = false;
  identiferStatus = '';
  form: UntypedFormGroup;
  errorCount = 0;
  telemetryImpression: IImpressionEventInput;
  telemetryCdata = [{
    id: 'user:account:recovery',
    type: 'Feature'
  }, {
    id: 'SB-13755',
    type: 'Task'
  }];
  constructor(public activatedRoute: ActivatedRoute, public resourceService: ResourceService, public formBuilder: UntypedFormBuilder,
    public toasterService: ToasterService, public router: Router, public recoverAccountService: RecoverAccountService,
    public recaptchaService: RecaptchaService, public telemetryService: TelemetryService) {
      try {
        this.googleCaptchaSiteKey = (<HTMLInputElement>document.getElementById('googleCaptchaSiteKey')).value;
      } catch (error) {
        this.googleCaptchaSiteKey = '';
      }
  }

  ngOnInit() {
    this.initializeForm();
    this.setTelemetryImpression();
  }
  initializeForm() {
    this.form = this.formBuilder.group({
      identifier: new UntypedFormControl(null, [Validators.required,
        Validators.pattern(/^([6-9]\d{9}|[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[a-z]{2,4})$/)]),
        name: new UntypedFormControl(null, [Validators.required])
    });
    this.form.valueChanges.subscribe(val => {
      this.nameNotExist = false;
      if (this.form.status === 'VALID') {
        this.disableFormSubmit = false;
      } else {
        this.disableFormSubmit = true;
      }
    });
    this.form.controls.identifier.valueChanges.subscribe(val => this.identiferStatus = '');
  }
  handleNext(captchaResponse?: string) {
    if (captchaResponse) {
      this.disableFormSubmit = true;
      this.recaptchaService.validateRecaptcha(captchaResponse).subscribe((data: any) => {
        if (_.get(data, 'result.success')) {
          this.initiateFuzzyUserSearch();
        }
      }, (error) => {
        const telemetryErrorData = {
          env: this.activatedRoute.snapshot.data.telemetry.env,
          errorMessage: _.get(error, 'error.params.errmsg') || '',
          errorType: 'SYSTEM', pageid: this.activatedRoute.snapshot.data.telemetry.pageid,
          stackTrace: JSON.stringify((error && error.error) || '')
        };
        this.telemetryService.generateErrorEvent(telemetryErrorData);
        this.resetGoogleCaptcha();
      });
    }
  }

  initiateFuzzyUserSearch() {
    this.recoverAccountService.fuzzyUserSearch(this.form.value).subscribe(response => {
      if (_.get(response, 'result.response.count') > 0) { // both match
        this.navigateToNextStep(response);
      } else { // both dint match
        this.identiferStatus = 'NOT_MATCHED';
        this.nameNotExist = true;
      }
    }, error => {
      this.resetGoogleCaptcha();
      if (error.responseCode === 'PARTIAL_SUCCESS_RESPONSE') {
        this.identiferStatus = 'MATCHED';
        this.handleError(error);
      } else {
        this.identiferStatus = 'NOT_MATCHED';
        this.nameNotExist = true;
      }
    });
  }

  resetGoogleCaptcha() {
    if (this.googleCaptchaSiteKey) {
      this.captchaRef.reset();
    }
  }

  navigateToNextStep(response) {
    this.recoverAccountService.fuzzySearchResults = _.get(response, 'result.response.content');
    this.router.navigate(['/recover/select/account/identifier'], {
      queryParams: this.activatedRoute.snapshot.queryParams
    });
  }
  handleError(error) {
    this.errorCount += 1;
    this.nameNotExist = true;
    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 = 'You have exceeded maximum retry. Please try 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 {

    }
  }
  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,
      }
    };
  }
}

results matching ""

    No results matching ""