241 lines
9.0 KiB
PHP
Executable File

<?php
$token=isset($verification_details->token)?$verification_details->token:'';
$created_on=isset($verification_details->created_on)?$verification_details->created_on:0;
$expiration_on=isset($verification_details->expiration_on)?$verification_details->expiration_on:0;
$send=isset($verification_details->send)&&$verification_details->send!=""?json_decode($verification_details->send):(object)[];
$via=isset($send->via)?$send->via:'';
$code=isset($send->code)?$send->code:'';
if($via=='email'){
$heading="Hi!, an Email has been sent to your email address <b>".$code."</b> with a verification code. Put the code in the box below and press continue to verify your account.";
}
else if($via=='phone'){
$heading="Hi!, an SMS has been sent to your mobile number <b>".$code."</b> with a verification code. Put the code in the box below and press continue to verify your account.";
}
?>
<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, shrink-to-fit=no" />
<meta name="description" content="">
<meta name="author" content="">
<title>WeCuro - Verification</title>
<style type="text/css">
body{
background-image: linear-gradient(rgba(208, 235, 233, 0.7), rgba(207, 235, 233, 0.7)), url(<?=base_url()?>common/frontend/assets/images/verification-page-image.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: top;
}
</style>
<?php $this->load->view('frontend/components/header'); ?>
</head>
<body>
<div class="container-fluid p-0 m-0">
<div class="root-wrapper w-100">
<div class="row w-100 m-auto" style="height:100vh;">
<div class="col-md-5 m-auto p-0">
<?php
if($token!="" && $expiration_on>time()){
?>
<h4 class="text-center mb-3 text-muted">
This Page will automatically get expired in <span class="page-killed-timer">00:00</span>
</h4>
<div class="card p-2 shadow ">
<div class="card-header">
<?=$heading?>
<a type="button" class="resend-otp-option" id="resendOtp" onclick="resendOTP('<?=$token?>')">Resend Code</a>
<span class="resend-otp-timer text-muted align-self-end"></span>
</div>
<div class="card-body">
<form
role="form"
action="<?=base_url()?>auth/hms_user_verification_authenticate"
method="post"
enctype="multipart/form-data"
name="newGenInfo"
class="form-dtre5dgsgdt6"
>
<input type="hidden" name="<?=$this->security->get_csrf_token_name()?>" value="<?=$this->security->get_csrf_hash()?>" />
<input type="hidden" name="token" value="<?=$token?>">
<div class="mb-3">
<input type="number" class="form-control" id="otp" name="otp" placeholder="******" min="0">
</div>
<button type="submit" class="btn btn-primary w-100" id="submitButton" name="authenticate" disabled>Continue</button>
</form>
</div>
</div>
<?php
}else{
?>
<div class="card" style="background:transparent;">
<div class="card-header text-center">
<h5>Opps! Verification Link Expired!</h5>
</div>
<div class="card-body">
<h5 class="card-title text-center" style="font-weight: 400;">
The verification links typically expire for security reasons after a certain time period, or the link has already been used.
</h5>
<p class="text-center mb-0">Go to <a href="<?=base_url()?>">Wecuro</a></p>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
<loader>
<?php $this->load->view('home_visit/loader'); ?>
</loader>
</div>
<?php
if($token!="" && $expiration_on>time()){
?>
<script type="text/javascript">
const otpInput=document.getElementById("otp");
const submitButton=document.getElementById("submitButton");
otpInput.addEventListener("input",function(){
if(otpInput.value.length>6) {
otpInput.value=otpInput.value.slice(0, 6);
}
if(otpInput.value.length===6){
submitButton.removeAttribute("disabled");
}
else{
submitButton.setAttribute("disabled", "disabled");
}
});
let timeRemainingNextOtp,timeRemainingPageKilled,timerIntervalOtp,timerIntervalPageKill;
$('.resend-otp-option').hide();
updateTimer();
startTimer();
function updateTimer() {
const minutes=Math.floor(timeRemainingNextOtp / 60);
const seconds=timeRemainingNextOtp % 60;
const formattedTime='Resend Code in '+`${minutes}:${(seconds < 10 ? '0' : '')}${seconds}`;
$('.resend-otp-timer').text(formattedTime);
if(timeRemainingNextOtp===0) {
clearInterval(timerIntervalOtp);
$('.resend-otp-timer').hide();
$('.resend-otp-option').show();
}
timeRemainingNextOtp--;
}
function pageKilledTimer() {
const minutes=Math.floor(timeRemainingPageKilled / 60);
const seconds=timeRemainingPageKilled % 60;
const formattedTime=`${minutes}:${(seconds < 10 ? '0' : '')}${seconds}`;
$('.page-killed-timer').text(formattedTime);
if(timeRemainingPageKilled===0) {
clearInterval(timerIntervalPageKill);
location.reload();
}
timeRemainingPageKilled--;
}
function startTimer(){
clearInterval(timerIntervalOtp);
clearInterval(timerIntervalPageKill);
timeRemainingPageKilled=(typeof timeRemainingPageKilled!=='undefined')?timeRemainingPageKilled:<?=$expiration_on-time()?>;
if(timeRemainingPageKilled>120){
timeRemainingNextOtp=120;
updateTimer();
timerIntervalOtp=setInterval(updateTimer, 1000);
}else{
$('.resend-otp-timer').hide();
}
pageKilledTimer();
timerIntervalPageKill=setInterval(pageKilledTimer, 1000);
}
function resendOTP(token){
var url="<?=base_url()?>auth/hms_user_verification_resend_otp";
$.ajax({
type: 'POST',
url: url,
data: {
<?=$this->security->get_csrf_token_name()?>:'<?=$this->security->get_csrf_hash()?>',
token: token
},
beforeSend: function(){
// console.log("resending otp...");
callLoader_hgy67vg(true,'Resending OTP...');
},
success: function(response) {
var data=$.parseJSON(response);
if(data.status==200){
$('.resend-otp-timer').show();
$('.resend-otp-option').hide();
startTimer();
}else{
swalAlert('error',data.msg);
}
callLoader_hgy67vg(false,'');
},
error: function(){
callLoader_hgy67vg(false,'');
console.error("something bad happened while calling ajax-auth/hms_user_verification_resend_otp");
},
complete: function(){
// console.log("completed resend otp...");
}
});
}
</script>
<script type="text/javascript">
if(typeof swalAlert==="undefined"){
function swalAlert(icon,msg,con=false,time=1500){
Swal.fire({
position: 'center',
icon: icon,
title: msg,
showConfirmButton: con,
timer: time
});
}
}
$(".form-dtre5dgsgdt6").submit(function(e){
e.preventDefault();
var form=$(this);
var actionUrl=form.attr('action');
$.ajax({
type: "POST",
url: actionUrl,
data: form.serialize(),
beforeSend: function(){
// console.log("submitting form: form-dtre5dgsgdt6");
callLoader_hgy67vg(true,'Authenticating...');
},
success: function(response) {
var response=$.parseJSON(response);
callLoader_hgy67vg(false,'');
if(response.status==200){
window.location.href='auth/login';
}else{
swalAlert('error',response.msg);
}
},
error: function(){
callLoader_hgy67vg(false,'');
console.error("something bad happened while calling ajax-"+actionUrl);
},
complete: function(){
// console.log("Completed form submitting: form-dtre5dgsgdt6");
}
});
});
</script>
<?php
}
?>
</body>
</html>