File
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Constructor
constructor(profileService: ProfileService, navParams: NavParams, popOverCtrl: PopoverController, platform: Platform, commonUtilService: CommonUtilService, menuCtrl: MenuController)
|
|
Parameters :
Name |
Type |
Optional |
profileService |
ProfileService
|
No
|
navParams |
NavParams
|
No
|
popOverCtrl |
PopoverController
|
No
|
platform |
Platform
|
No
|
commonUtilService |
CommonUtilService
|
No
|
menuCtrl |
MenuController
|
No
|
|
userId
|
Type : string
|
|
Key may be phone or email depending on the verification flow from which it is called
|
Methods
ionViewWillEnter
|
ionViewWillEnter()
|
|
|
ionViewWillLeave
|
ionViewWillLeave()
|
|
|
Async
resendOTP
|
resendOTP()
|
|
|
enableResend
|
Default value : true
|
|
invalidOtp
|
Default value : false
|
|
otp
|
Type : string
|
Default value : ''
|
|
Public
platform
|
Type : Platform
|
|
Public
popOverCtrl
|
Type : PopoverController
|
|
remainingAttempts
|
Type : any
|
|
unregisterBackButton
|
Type : any
|
|
import { Component, Inject, Input } from '@angular/core';
import { ProfileConstants, OTPTemplates } from '@app/app/app.constant';
import { CommonUtilService } from '@app/services/';
import { MenuController, NavParams, Platform, PopoverController } from '@ionic/angular';
import { GenerateOtpRequest, HttpClientError, ProfileService, VerifyOtpRequest } from 'sunbird-sdk';
@Component({
selector: 'app-edit-contact-verify-popup',
templateUrl: './edit-contact-verify-popup.component.html',
styleUrls: ['./edit-contact-verify-popup.component.scss'],
})
export class EditContactVerifyPopupComponent {
/**
* Key may be phone or email depending on the verification flow from which it is called
*/
@Input() userId: string;
@Input() key: string;
@Input() title: string;
@Input() description: string;
@Input() type: string;
otp = '';
invalidOtp = false;
enableResend = true;
unregisterBackButton: any;
remainingAttempts: any;
constructor(
@Inject('PROFILE_SERVICE') private profileService: ProfileService,
private navParams: NavParams,
public popOverCtrl: PopoverController,
public platform: Platform,
private commonUtilService: CommonUtilService,
private menuCtrl: MenuController
) {
this.userId = this.navParams.get('userId');
this.key = this.navParams.get('key');
this.title = this.navParams.get('title');
this.description = this.navParams.get('description');
this.type = this.navParams.get('type');
}
ionViewWillEnter() {
this.menuCtrl.enable(false);
this.unregisterBackButton = this.platform.backButton.subscribeWithPriority(11, () => {
this.popOverCtrl.dismiss();
this.unregisterBackButton.unsubscribe();
});
}
verify() {
if (this.commonUtilService.networkInfo.isNetworkAvailable) {
let req: VerifyOtpRequest;
if (this.type === ProfileConstants.CONTACT_TYPE_PHONE) {
req = {
key: this.key,
type: ProfileConstants.CONTACT_TYPE_PHONE,
otp: this.otp,
...( this.key && this.key.match(/(([a-z]|[A-Z])+[*]+([a-z]*[A-Z]*[0-9]*)*@)|([0-9]+[*]+[0-9]*)+/g) &&
{ userId: this.userId })
};
} else {
req = {
key: this.key,
type: ProfileConstants.CONTACT_TYPE_EMAIL,
otp: this.otp,
...( this.key && this.key.match(/(([a-z]|[A-Z])+[*]+([a-z]*[A-Z]*[0-9]*)*@)|([0-9]+[*]+[0-9]*)+/g) &&
{ userId: this.userId })
};
}
this.profileService.verifyOTP(req).toPromise()
.then(() => {
this.popOverCtrl.dismiss({ OTPSuccess: true, value: this.key });
})
.catch(error => {
if (HttpClientError.isInstance(error)
&& error.response.responseCode === 400) {
if (typeof error.response.body === 'object') {
if (error.response.body.params.err === 'UOS_OTPVERFY0063' &&
error.response.body.result.remainingAttempt > 0) {
this.remainingAttempts = error.response.body.result.remainingAttempt;
this.otp = '';
this.invalidOtp = true;
} else {
this.popOverCtrl.dismiss();
this.commonUtilService.showToast('OTP_FAILED');
}
}
}
});
} else {
this.commonUtilService.showToast('INTERNET_CONNECTIVITY_NEEDED');
}
}
async resendOTP() {
if (this.commonUtilService.networkInfo.isNetworkAvailable) {
this.enableResend = !this.enableResend;
let req: GenerateOtpRequest;
if (this.type === ProfileConstants.CONTACT_TYPE_PHONE) {
req = {
key: this.key,
type: ProfileConstants.CONTACT_TYPE_PHONE,
...( this.key && this.key.match(/(([a-z]|[A-Z])+[*]+([a-z]*[A-Z]*[0-9]*)*@)|([0-9]+[*]+[0-9]*)+/g) &&
{ userId: this.userId, templateId: OTPTemplates.EDIT_CONTACT_OTP_TEMPLATE })
};
} else {
req = {
key: this.key,
type: ProfileConstants.CONTACT_TYPE_EMAIL,
...( this.key && this.key.match(/(([a-z]|[A-Z])+[*]+([a-z]*[A-Z]*[0-9]*)*@)|([0-9]+[*]+[0-9]*)+/g) &&
{ userId: this.userId, templateId: OTPTemplates.EDIT_CONTACT_OTP_TEMPLATE })
};
}
let loader = await this.commonUtilService.getLoader();
await loader.present();
this.profileService.generateOTP(req).toPromise()
.then(async () => {
this.commonUtilService.showToast('OTP_RESENT');
await loader.dismiss();
loader = undefined;
})
.catch(async (e) => {
if (loader) {
this.commonUtilService.showToast('SOMETHING_WENT_WRONG');
await loader.dismiss();
loader = undefined;
}
});
} else {
this.commonUtilService.showToast('INTERNET_CONNECTIVITY_NEEDED');
}
}
cancel() {
this.popOverCtrl.dismiss({ OTPSuccess: false });
}
ionViewWillLeave() {
this.menuCtrl.enable(true);
if (this.unregisterBackButton) {
this.unregisterBackButton.unsubscribe();
}
}
}
<ion-content>
<div class="ecv-header ion-text-center">
<h6 class="M0">{{title | titlecase}}</h6>
</div>
<ion-grid>
<ion-row>
<ion-col size="12" class="text-center ion-no-padding">
<p class="f14" style="color: #4a4a4a">{{description}}</p>
</ion-col>
<section class="text-center W100" *ngIf="type==='phone'">
<ion-label class="font-weight-bold ion-text-center">{{'ENTER_OTP' | translate}}</ion-label>
<ion-col size="12" class="text-center ion-no-padding" *ngIf="invalidOtp">
<p class="error">{{'ERROR_OTP' | translate:{'%s': remainingAttempts} }}</p>
</ion-col>
<ion-col size="12" class="text-center ion-no-padding">
<div class="W100 merged-input-container MT10">
<ion-input type="tel" placeholder="{{'OTP_PLACEHOLDER' | translate }}" class="form-control"
[(ngModel)]="otp"></ion-input>
</div>
</ion-col>
</section>
<section class="text-center W100" *ngIf="type==='email'">
<ion-row>
<ion-col size="12" class="text-center ion-no-padding">
<strong>{{'ENTER_OTP' | translate}}</strong>
</ion-col>
<ion-col size="12" class="text-center ion-no-padding" *ngIf="invalidOtp">
<p class="error">{{'ERROR_OTP' | translate:{'%s': remainingAttempts} }}</p>
</ion-col>
<ion-col size="12" class="text-center ion-no-padding">
<div class="W100 merged-input-container MT10">
<ion-input type="tel" placeholder="{{'OTP_PLACEHOLDER' | translate }}" class="form-control"
[(ngModel)]="otp"></ion-input>
</div>
</ion-col>
</ion-row>
</section>
<ion-col size="12" class="text-center ion-no-padding">
<ion-button fill="clear" (click)="resendOTP();" [disabled]="!enableResend">{{'RESEND_OTP' | translate}}
</ion-button>
</ion-col>
</ion-row>
</ion-grid>
<ion-row>
<ion-col class="ion-padding">
<ion-button expand="block" fill="outline" (click)="cancel()">{{ 'CANCEL' | translate }} </ion-button>
</ion-col>
<ion-col class="ion-padding">
<ion-button expand="block" (click)="verify()">{{ 'BTN_SUBMIT' | translate }} </ion-button>
</ion-col>
</ion-row>
</ion-content>
@import "src/assets/styles/_variables.scss";
:host {
.merged-input-container {
border: 1px solid $form-input-border-active-color;
display: flex;
flex: 1 1 auto;
border-radius: 4px;
.decorator {
display: inline-block;
max-width: 2.813rem;
}
}
.ecv-header {
background-color: #{$blue};
color: map-get($colors, white);
padding: 16px 0;
}
ion-button{
--background: #{$blue} !important;
color: map-get($colors, white);
--background-hover: #{$blue} !important;
--background-activated: #{$blue} !important;
}
ion-button[fill="outline"]{
--background: map-get($colors, white) !important;
color: #{$blue};
--border-color: #{$blue};
}
ion-button[fill="clear"]{
--background: map-get($colors, white) !important;
color: #{$blue};
}
}
Legend
Html element with directive