import { Component, OnInit, ViewChild, ChangeDetectorRef, OnDestroy } from '@angular/core'; import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { AuthenticationService } from 'src/app/hmg-common/services/authentication/authentication.service'; import { Router } from '@angular/router'; import { AlertController } from '@ionic/angular'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { CheckUserAuthenticationRequest } from 'src/app/hmg-common/services/authentication/models/check-user-auth.request'; import { CheckUserAuthenticationResponse } from 'src/app/hmg-common/services/authentication/models/check-user-auth.response'; import { CheckActivationCodeRequest } from 'src/app/hmg-common/services/authentication/models/check-activation-code.request'; import { SmsReaderService } from 'src/app/hmg-common/services/sms/sms-reader.service'; import { ForgotFileIDResponse } from '../../hmg-common/services/authentication/models/forgot-File-ID.response'; import { InternationalMobileComponent } from 'src/app/hmg-common/ui/mobile-number/international-mobile/international-mobile.component'; import { CountryCode } from 'src/app/hmg-common/ui/mobile-number/international-mobile/models/country-code.model'; import { ForgetPassword } from '../models/forget.password'; import { LoginModel } from '../models/LoginModel'; import { SharedDataService } from 'src/app/hmg-common/services/shared-data-service/shared-data.service'; @Component({ selector: 'app-forgot', templateUrl: './forgot.component.html', styleUrls: ['./forgot.component.scss'] }) export class ForgotComponent implements OnInit,OnDestroy { private loginData = new LoginModel(); public P_NEW_PASSWORD: string; public P_Confirm_NEW_PASSWORD : string; public P_USER_NAME : string; @ViewChild(InternationalMobileComponent) internationlMobile: InternationalMobileComponent; constructor( public cs: CommonService, public authService: AuthenticationService, public router: Router, public alertController: AlertController, public ts: TranslatorService, public smsService: SmsReaderService, public changeDetector: ChangeDetectorRef, public sharedData: SharedDataService ) { } ngOnInit() { } ngOnDestroy(): void { this.smsService.stopSMSMonitoring(); } public onForgot() { this.sendSMSForForgotPassword(); } private checkUserResult: CheckUserAuthenticationResponse; private sendSMSForForgotPassword() { const request = new ForgetPassword(); this.authService.sendForgetPassword( request, () => { this.sendSMSForForgotPassword(); }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { if (this.cs.validResponse(result)) { this.checkUserResult = result; } }); } public forgotpassword(){ const data = this.sharedData.getSharedData("logindata", false); this.loginData.P_USER_NAME = this.P_USER_NAME; let request:ForgetPassword = new ForgetPassword(); request.P_Confirm_NEW_PASSWORD=this.P_NEW_PASSWORD; request.P_NEW_PASSWORD=this.P_Confirm_NEW_PASSWORD; request.P_USER_NAME = data.P_USER_NAME; this.authService.submitForgetPassword( request, () => { //this.sendSMSForForgotPassword(); }, this.ts.trPK('general', 'ok')).subscribe((result: CheckUserAuthenticationResponse) => { if (this.cs.validResponse(result)) { this.checkUserResult = result; console.log(result); this.cs.toastPK("changePassword","passwordchanged"); this.cs.openLogin(); } }); } }