PK

ADDRLIN : /home/anibklip/aelogifts.com/
FLL :
Current File : /home/anibklip/aelogifts.com/login.php

<?php
include "conn.php";
if ($_GET['paction'] == "logout") {
	session_destroy();
}

if ($_POST['login_btn'] != "") {
	$login = login($_POST['email'], $_POST['pass'], $_POST['remember']);
	if ($login) {
		if ($_SESSION['url'] != "") {
			$u = $_SESSION['url'];
			$_SESSION['url'] = "";
			//header("Location:http://".$_SERVER[SERVER_NAME].$u);
			header("Location:$u");
			echo "<script>window.location.href='$u'</script>";
			die();
		} else {
			header("Location:index.php");
			echo "<script>window.location.href='index.php'</script>";
			die();
		}
	} else {
		$msg = "Oops..! &nbsp; &nbsp; Invalid Email / Password";
	}
}

// die($_POST);
if ($_POST['login_otp_btn'] != "") {
	// echo "ssssssssssssssss";die;
	$login = loginOtp($_POST['mobile'], $_POST['otp']);
	// var_dump($login);
	if ($login) {
		if ($_SESSION['url'] != "") {
			$u = $_SESSION['url'];
			$_SESSION['url'] = "";
			//header("Location:http://".$_SERVER[SERVER_NAME].$u);
			header("Location:$u");
			echo "<script>window.location.href='$u'</script>";
			die();
		} else {
			header("Location:index.php");
			echo "<script>window.location.href='index.php'</script>";
			die();
		}
	} else {
		$msg = "Oops..! &nbsp; &nbsp; Invalid OTP Try again";
	}
}

if ($_GET['action'] == "logout") {
	$logout = logout();
	if ($logout) {
		session_destroy();
		header('location: index.php');
		echo "<script>window.location.href='index.php'</script>";
		die();
	}
}

if ($_SESSION['member_id'] != "") {
	echo "<script>window.location.href='index.php'</script>";
	header('location: index.php');
	die();
}

include "header.php";

$qq = "SELECT * from cate where ctid='" . $_GET['ctid'] . "'";
$qq = mysqli_query($conn, $qq) or die(mysqli_error($conn,));
if ($r = mysqli_fetch_array($qq)) {
	$parent_id = $r['parent_id'];
	$cate = $r['bname'];
}
?>
<div class="breadcrumb-section">
	<div class="container">
		<h2>Customer's login</h2>
		<nav class="theme-breadcrumb">
			<ol class="breadcrumb">
				<li class="breadcrumb-item">
					<a href="index.html">Home</a>
				</li>
				<li class="breadcrumb-item active">Customer's login</li>
			</ol>
		</nav>
	</div>
</div>

<section class="login-page section-b-space">
	<div class="container">
		<div class="row">
			<div class="col-lg-6">
				<h3>Login</h3>
				<div class="theme-card">
					<?php if($msg){?> <div class="alert alert-danger text-center" role="alert"> <?php echo $msg;?> </div> <?php } ?>
					
					<form class="theme-form <?php echo ($_POST['login_otp_btn']==1 && $login==false?"":"d-none")?>" action="" method="post" id="passwordLoginForm">
						<div class="form-box">
							<label for="email" class="form-label">Email</label>
							<input type="text" class="form-control" name="email" id="email" placeholder="Email" required="">
						</div>
						<div class="form-box">
							<label for="pass" class="form-label">Password</label>
							<input type="password" class="form-control" name="pass" id="pass" placeholder="Enter your password" required="">
						</div>
						<input name="login_btn" type="submit" value="Login" class="btn btn-solid" />
						<a id="switchToOtp" href="javascript:;">Login with OTP</a>
					</form>

					<!-- OTP Login -->
					<form class="theme-form <?php echo ($_POST['login_otp_btn']==1 && $login==false?"d-none":"")?>" action="" method="post" id="otpLoginForm">
						<div class="form-box">
							<label for="mobile" class="form-label">Mobile</label>
							<input type="text" class="form-control" name="mobile" id="mobile" placeholder="Mobile" value="<?php echo $_POST['mobile'];?>" required="">
						</div>
						<div class="form-box <?php echo ($_POST['login_otp_btn']==1 && $login==false?"":"d-none")?>" id="verifyOtpForm">
							<div class="text-success mb-3" id="otp_success">OTP has been sent to your registered mobile.</div>
							<label for="otp" class="form-label">Enter OTP</label>
							<input type="text" class="form-control" id="otp" name="otp" placeholder="OTP" required />
							<button type="submit" name="login_otp_btn" value="1" id="verifyOtpbtn" class="btn btn-solid">Login</button>
							<div class="mt-3">
								<span id="timer" class="text-muted"></span>
								<button type="button" class="btn btn-link" id="resendOtpButton" disabled>Resend OTP</button>
							</div>
						</div>
						<button type="button" class="btn btn-solid <?php echo ($_POST['login_otp_btn']==1 && $login==false?"d-none":"")?>" id="generateOtpButton">Generate OTP</button>
						<div class="mt-4">
							<a id="switchToPassword" href="javascript:;">Login with Password</a>
						</div>
					</form>
				</div>
			</div>
			<div class="col-lg-6 right-login">
				<h3>New Customer</h3>
				<div class="theme-card authentication-right">
					<h6 class="title-font">Create An Account</h6>
					<p>Sign up for a free account at our store. Registration is quick and easy. It allows you to be
						able to order from our shop. To start shopping click register.</p>
					<a href="register.html" class="btn btn-solid">Create an Account</a>
				</div>
			</div>
		</div>
	</div>
</section>

<script>
	$(document).ready(function() {
		let username = ''; // Store the username for OTP verification
		let countdown;
		let timeLeft;

		function startTimer() {
			timeLeft = 120; // 2 minutes in seconds
			$('#resendOtpButton').prop('disabled', true);
			
			countdown = setInterval(function() {
				const minutes = Math.floor(timeLeft / 60);
				const seconds = timeLeft % 60;
				$('#timer').text(`Time remaining: ${minutes}:${seconds < 10 ? '0' : ''}${seconds}`);
				
				if (timeLeft <= 0) {
					clearInterval(countdown);
					$('#timer').text('');
					$('#resendOtpButton').prop('disabled', false);
				}
				timeLeft--;
			}, 1000);
		}

		// Step 1: Generate OTP
		function generateOTP(mobile) {
			if (!mobile) {
				alert('Please enter a mobile.');
				return;
			}

			// Send request to generate OTP
			$.get('ajax.php?action=GenerateOtp', { mobile }, function(res) {
				res=JSON.parse(res);
				// alert(res.success);
				if (res.success) {
					$('#generateOtpButton').addClass('d-none');
					$('#verifyOtpForm').removeClass('d-none');
					startTimer();
				} else {
					alert('Failed to generate OTP. Please try again.');
				}
			}).fail(function() {
				alert('Error!...Failed to generate OTP. Please try again after some time.');
			});
		}

		$('#generateOtpButton').click(function() {
			const mobile = $('#mobile').val();
			generateOTP(mobile);
		});

		// Resend OTP handler
		$('#resendOtpButton').click(function() {
			const mobile = $('#mobile').val();
			generateOTP(mobile);
		});

		// Switch to OTP Login Form
		$('#switchToOtp').click(function() {
			$('#passwordLoginForm').addClass('d-none');
			$('#otpLoginForm').removeClass('d-none');
		});

		// Switch to Password Login Form
		$('#switchToPassword').click(function() {
			$('#otpLoginForm').addClass('d-none');
			$('#passwordLoginForm').removeClass('d-none');
			// Clear any existing timer when switching forms
			if (countdown) {
				clearInterval(countdown);
				$('#timer').text('');
			}
		});
	});
</script>
<?php include "footer.php"; ?>


PK 99