File

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

Constructor

constructor(tenantService: any, learnerService: any, configService: any)

Methods

Private setTenantInfo
setTenantInfo()
Returns: void
fuzzyUserSearch
fuzzyUserSearch(data: any)
Returns: void
getIdentifierType
getIdentifierType(value: any)
Returns: void
resetPassword
resetPassword(data: any)
Returns: void
generateOTP
generateOTP(data: any)
Returns: void
verifyOTP
verifyOTP(data: any)
Returns: void

Properties

configService
configService: any
fuzzySearchResults
fuzzySearchResults: any[]
learnerService
learnerService: any
otpVerified
otpVerified: boolean
Default value: true
selectedAccountIdentifier
selectedAccountIdentifier: any
tenantInfo
tenantInfo: 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) {
    const options = {
      url: this.configService.urlConFig.URLS.ACCOUNT_RECOVERY.FUZZY_SEARCH,
      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) {
    const options = {
      url: this.configService.urlConFig.URLS.OTP.GENERATE,
      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 ""