File

src/app/modules/recover-account/services/recover-account/recover-account.service.ts

Index

Properties
Methods

Constructor

constructor(tenantService: TenantService, learnerService: LearnerService, configService: ConfigService)
Parameters :
Name Type Optional
tenantService TenantService No
learnerService LearnerService No
configService ConfigService No

Methods

fuzzyUserSearch
fuzzyUserSearch(data: any, captchaResponse?: string)
Parameters :
Name Type Optional
data any No
captchaResponse string Yes
Returns : any
generateOTP
generateOTP(data, captchaResponse?)
Parameters :
Name Optional
data No
captchaResponse Yes
Returns : any
getIdentifierType
getIdentifierType(value)
Parameters :
Name Optional
value No
Returns : "phone" | "email"
resetPassword
resetPassword(data: any)
Parameters :
Name Type Optional
data any No
Returns : any
Private setTenantInfo
setTenantInfo()
Returns : void
verifyOTP
verifyOTP(data)
Parameters :
Name Optional
data No
Returns : any

Properties

Public configService
Type : ConfigService
fuzzySearchResults
Type : Array<any>
Default value : []
Public learnerService
Type : LearnerService
otpVerified
Default value : true
selectedAccountIdentifier
Type : any
Default value : {}
tenantInfo
Type : any
import { ConfigService } from '@sunbird/shared';
import { Injectable } from '@angular/core';
import { TenantService, LearnerService } from '@sunbird/core';
import { first } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class RecoverAccountService {

  tenantInfo: any;
  fuzzySearchResults: Array<any> = [];
  selectedAccountIdentifier: any = {};
  otpVerified = true;
  constructor(private tenantService: TenantService, public learnerService: LearnerService, public configService: ConfigService) {
    this.setTenantInfo();
  }
  private setTenantInfo() {
    this.tenantService.tenantData$.pipe(first()).subscribe(data => {
      if (!data.err) {
        this.tenantInfo = {
          logo: data.tenantData.logo,
          tenantName: data.tenantData.titleName
        };
      }
    });
  }
  fuzzyUserSearch(data: any, captchaResponse?: string) {
    const options = {
      url: this.configService.urlConFig.URLS.ACCOUNT_RECOVERY.FUZZY_SEARCH + '?captchaResponse=' + captchaResponse,
      data: {
        request: {
          filters: {
            'isDeleted' : 'false',
            fuzzy: {
              firstName: data.name
            }
          }
        }
      }
    };
    if (this.getIdentifierType(data.identifier) === 'phone') {
      options.data.request.filters['$or'] = {
        phone: data.identifier,
        prevUsedPhone: data.identifier
      };
    } else {
      options.data.request.filters['$or'] = {
        email: data.identifier,
        prevUsedEmail: data.identifier
      };
    }
    return this.learnerService.post(options);
  }
  getIdentifierType(value) {
    value = Number(value);
    const phoneRegX = new RegExp(/^[6-9]\d{9}$/);
    if (phoneRegX.test(value)) {
      return 'phone';
    } else {
      return 'email';
    }
  }
  resetPassword(data: any) {
    const options = {
      url: this.configService.urlConFig.URLS.ACCOUNT_RECOVERY.RESET_PASSWORD,
      data: data
    };
    return this.learnerService.post(options);
  }
  generateOTP(data, captchaResponse?) {
    const options = {
      url: this.configService.urlConFig.URLS.OTP.ANONYMOUS.GENERATE + '?captchaResponse=' + captchaResponse,
      data: data
    };
    return this.learnerService.post(options);
  }
  verifyOTP(data) {
    const options = {
      url: this.configService.urlConFig.URLS.OTP.VERIFY,
      data: data
    };
    return this.learnerService.post(options);
  }
}

results matching ""

    No results matching ""