Skip to content

Commit

Permalink
Merge pull request #469 from GSuma21/release-2.6.1
Browse files Browse the repository at this point in the history
issue #fix captcha
  • Loading branch information
Cafnanc authored Apr 4, 2024
2 parents 20902ec + 4e183ca commit cdba2db
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 62 deletions.
6 changes: 3 additions & 3 deletions src/app/core/services/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export class AuthService {
private util: UtilService
) { }

async createAccount(formData,captchaToken:any) {
async createAccount(formData) {
this.deviceInfo = await this.util?.deviceDetails();
await this.loaderService.startLoader();
const config = {
url: urlConstants.API_URLS.CREATE_ACCOUNT,
payload: formData,
headers: captchaToken ? {'captcha-token': captchaToken, 'device-info': this.deviceInfo}:{}
};
headers: {'device-info': this.deviceInfo}
}
try {
let data: any = await this.httpService.post(config);
await this.setUserInLocal(data);
Expand Down
14 changes: 8 additions & 6 deletions src/app/core/services/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ export class ProfileService {
});
}

async generateOtp(formData) {
async generateOtp(formData,captchaToken) {
await this.loaderService.startLoader();
const config = {
url: urlConstants.API_URLS.GENERATE_OTP,
payload: formData
payload: formData,
headers: captchaToken ? {'captcha-token': captchaToken}:{}
};
try {
let data: any = await this.httpService.post(config);
Expand All @@ -93,13 +94,13 @@ export class ProfileService {
this.loaderService.stopLoader();
}
}
async updatePassword(formData,captchaToken) {
async updatePassword(formData) {
this.deviceInfo = await this.util?.deviceDetails()
await this.loaderService.startLoader();
const config = {
url: urlConstants.API_URLS.RESET_PASSWORD,
payload: formData,
headers: captchaToken ? {'captcha-token': captchaToken, 'device-info': this.deviceInfo}:{}
headers: { 'device-info': this.deviceInfo}
};
try {
let data: any = await this.httpService.post(config);
Expand All @@ -116,11 +117,12 @@ export class ProfileService {
return null;
}
}
async registrationOtp(formData) {
async registrationOtp(formData,captchaToken) {
await this.loaderService.startLoader();
const config = {
url: urlConstants.API_URLS.REGISTRATION_OTP,
payload: formData
payload: formData,
headers: captchaToken ? {'captcha-token': captchaToken}:{}
};
try {
let data: any = await this.httpService.post(config);
Expand Down
82 changes: 47 additions & 35 deletions src/app/pages/auth/otp/otp.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,56 @@
<div class="mx-10">
<app-generic-header [labels]="labels"></app-generic-header>
</div>
<section>
<div class="otp-field">
<ng-otp-input (onInputChange)="onOtpChange($event)" [config]="config" #ngOtpInput></ng-otp-input>
</div>
<p class="hint-message"> {{"YOU_WILL_RECIEVE_OTP_IN_YOUR_EMAIL" | translate}}</p>
</section>
<section class="t-and-c d-flex" *ngIf="this.actionType == 'signup'">


<ion-item >
<ion-checkbox label-placement="stacked" alignment="start" slot="start" class="check-box" (ionChange)="checkboxClick($event)"></ion-checkbox>
<p class="t-and-c-text">{{"TERMS_AND_CONDITION"|translate}}
<a class='links'
[href]="privacyPolicyUrl" target="_blank">{{"PRIVACY_POLICY"|translate}}</a> & <a
class='links' [href]="termsOfServiceUrl" target="_blank">{{"TERMS_OF_SERVICE"|translate}}</a>
</p>
</ion-item>

</section>
<section>
<div *ngIf="siteKey" class="d-flex flex-justify-center">
<re-captcha (resolved)="onCaptchaResolved($event)" [siteKey]="siteKey" ></re-captcha>
</div>
</section>
<div *ngIf="!showOtp">
<section>
<div *ngIf="siteKey" class="d-flex flex-justify-center">
<re-captcha (resolved)="onCaptchaResolved($event)" [siteKey]="siteKey" ></re-captcha>
</div>
</section>
<section>
<div class="d-flex flex-justify-center flex-align-items-center">
<ion-button [ngClass]="{'my-10': true, 'disabled': !recaptchaResolved , 'onboard-button':true}" [disabled]="!recaptchaResolved"
(click)="onSubmitGenerateOtp()" shape="round">
{{'GENERATE_OTP'|translate}}
</ion-button>
</div>
</section>
</div>
<div *ngIf="showOtp">
<section>
<div class="otp-field">
<ng-otp-input (onInputChange)="onOtpChange($event)" [config]="config" #ngOtpInput></ng-otp-input>
</div>
<p class="hint-message"> {{"YOU_WILL_RECIEVE_OTP_IN_YOUR_EMAIL" | translate}}</p>
</section>
<section class="t-and-c d-flex" *ngIf="this.actionType == 'signup'">

<section>
<div class="d-flex flex-justify-center flex-align-items-center">
<ion-button [ngClass]="{'my-10': true, 'disabled': !checked || !isEnabled , 'onboard-button':true}" [disabled]="!checked || !isEnabled || !recaptchaResolved"
(click)="onSubmit()" shape="round">
{{'VERIFY_AND_LOGIN'|translate}}
</ion-button>

<ion-item >
<ion-checkbox label-placement="stacked" alignment="start" slot="start" class="check-box" (ionChange)="checkboxClick($event)"></ion-checkbox>
<p class="t-and-c-text">{{"TERMS_AND_CONDITION"|translate}}
<a class='links'
[href]="privacyPolicyUrl" target="_blank">{{"PRIVACY_POLICY"|translate}}</a> & <a
class='links' [href]="termsOfServiceUrl" target="_blank">{{"TERMS_OF_SERVICE"|translate}}</a>
</p>
</ion-item>

</section>
<section>
<div class="d-flex flex-justify-center flex-align-items-center">
<ion-button [ngClass]="{'my-10': true, 'disabled': !checked || !isEnabled , 'onboard-button':true}" [disabled]="!checked || !isEnabled || !recaptchaResolved"
(click)="onSubmit()" shape="round">
{{'VERIFY_AND_LOGIN'|translate}}
</ion-button>
</div>
</section>
<div class="d-flex flex-justify-center flex-align-items-center resend-otp">
<div class="counter" *ngIf="countDownTimer">{{'TRY_AGAIN_AFTER'|translate}} {{countDownTimer}}
{{'SECONDS'|translate}}</div>
<p class="underline" (click)="enableResendOtp && resendOtp()" [ngClass]="{'enable': enableResendOtp}">{{"RESEND_OTP"|translate}}</p>
</div>
</section>
<div class="d-flex flex-justify-center flex-align-items-center resend-otp">
<div class="counter" *ngIf="countDownTimer">{{'TRY_AGAIN_AFTER'|translate}} {{countDownTimer}}
{{'SECONDS'|translate}}</div>
<p class="underline" (click)="enableResendOtp && resendOtp()" [ngClass]="{'enable': enableResendOtp}">{{"RESEND_OTP"|translate}}</p>
</div>

</div>
</ion-col>
</ion-row>
Expand Down
24 changes: 14 additions & 10 deletions src/app/pages/auth/otp/otp.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class OtpPage implements OnInit {
termsOfServiceUrl = environment.termsOfServiceUrl;
captchaToken:any="";
recaptchaResolved: boolean = this.siteKey ? false : true;
showOtp:any = false;


constructor(private router: Router, private profileService: ProfileService,private location: Location, private activatedRoute: ActivatedRoute, private localStorage: LocalStorageService, private translateService: TranslateService, private authService: AuthService, private toast: ToastService, private menuCtrl: MenuController, private nav: NavController) {
Expand All @@ -67,7 +68,6 @@ export class OtpPage implements OnInit {
ngOnInit() {
this.labels = this.actionType == 'signup' ? ['VERIFY_ACCOUNT'] : ['ENTER_OTP'];
this.translateText();
this.startCountdown();
}

async translateText() {
Expand Down Expand Up @@ -101,19 +101,15 @@ export class OtpPage implements OnInit {
if (this.actionType == "signup") {
this.signupData.otp = this.otp;
this.signupData.has_accepted_terms_and_conditions = this.checked;
let result = await this.authService.createAccount(this.signupData, this.captchaToken);
if(result === null){
this.captchaComponent.reset();
}else if(result !== null){
let result = await this.authService.createAccount(this.signupData);
if(result){
this.router.navigate([`/${CommonRoutes.TABS}/${CommonRoutes.HOME}`], { replaceUrl: true });
this.menuCtrl.enable(true);
}
} else {
this.resetPasswordData.otp = this.otp;
let response = await this.profileService.updatePassword(this.resetPasswordData,this.captchaToken);
if(response === null){
this.captchaComponent.reset();
}else if(response !== null){
let response = await this.profileService.updatePassword(this.resetPasswordData);
if(response){
this.router.navigate([`${CommonRoutes.TABS}/${CommonRoutes.HOME}`], { replaceUrl: true })
this.menuCtrl.enable(true);
}
Expand All @@ -122,10 +118,18 @@ export class OtpPage implements OnInit {

async resendOtp() {
this.enableResendOtp = false;
var response = this.actionType == "signup" ? await this.profileService.registrationOtp(this.signupData) : await this.profileService.generateOtp({ email: this.resetPasswordData.email, password: this.resetPasswordData.password});
this.showOtp = false;
}

async onSubmitGenerateOtp(){
var response = this.actionType == "signup" ? await this.profileService.registrationOtp(this.signupData, this.captchaToken) : await this.profileService.generateOtp({ email: this.resetPasswordData.email, password: this.resetPasswordData.password},this.captchaToken);
if (response) {
this.toast.showToast(response.message, "success");
this.showOtp = true
this.startCountdown();
}else{
this.captchaComponent.reset();
this.location.back()
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/app/pages/auth/register/register.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ export class RegisterPage implements OnInit {
async createUser() {
let formJson = this.form1.myForm.value;
if (_.isEqual(formJson.password, formJson.cPassword)) {
let result = await this.profileService.registrationOtp(formJson);
if (result) {
this.toastService.showToast(result.message, "success")
this.router.navigate([`/${CommonRoutes.AUTH}/${CommonRoutes.OTP}`], { state: { type: "signup", formData: formJson } });
}
} else {
this.toastService.showToast('Password does not match.', 'danger');
}
Expand Down
3 changes: 0 additions & 3 deletions src/app/pages/auth/reset-password/reset-password.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ export class ResetPasswordPage implements OnInit {
let formJson = this.form1.myForm.value;
if (this.form1.myForm.valid) {
if (_.isEqual(formJson.password, formJson.newPassword)) {
var response = await this.profileService.generateOtp({ email: this.form1.myForm.value.email, password:formJson.password });
if (response) {
this.router.navigate([`/${CommonRoutes.AUTH}/${CommonRoutes.OTP}`], { state: { type: "reset-password", email: formJson.email, password: formJson.password } });
}
} else {
this.toastService.showToast('Please enter the same password', 'danger');
}
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,6 @@
"YOUR_CURRENT_DEVICE": "Your current device ",
"LOGGED_IN": "Logged in",
"LOGGED_OUT_AT": "Logged out at",
"EXPIRED": "Expired"
"EXPIRED": "Expired",
"GENERATE_OTP":"Generate otp"
}

0 comments on commit cdba2db

Please sign in to comment.