BBnepal-Accounts/application/views/admin/login.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

136 lines
5.2 KiB
PHP

<div class="login-wrap">
<div class="login-box-cover-outter">
<div class="login-box-cover">
<div class="login-heading">
<!-- <h3>Welcome To</h3>-->
<h2><?= $school_info['school_name']; ?><br> Admin Portal</h2>
<?php
$uname = '';
$pass = '';
$rme = 'Off';
if (isset($_COOKIE["username"]))
$uname = $_COOKIE["username"];
if (isset($_COOKIE["password"]))
$pass = $_COOKIE["password"];
if (isset($_COOKIE["rem_me"]))
$rme = $_COOKIE["rem_me"];
?>
</div>
<div class="login-box">
<?php if ($this->session->flashdata('success')) { ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<p><?php echo $this->session->flashdata('success') ?></p>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<?php } ?>
<h3>Login</h3>
<form id="loginform" method="post">
<div class="login-row">
<label class="login-lbl">
Email Address*
</label>
<input type="Email" name="email" id="email" value='<?php echo $uname; ?>' placeholder="Enter email address">
<p id="email_error" style="color:red;"></p>
</div>
<div class="login-row">
<label class="login-lbl">
Password*
</label>
<input type="password" name="password" id="password" value='<?php echo $pass; ?>' placeholder="Enter password" class="password_hide">
<span class="passwrd-icon icon-y"><i class="far fa-eye"></i></span>
<p id="password_error" style="color:red;"></p>
<p id="invalid_error" style="color:red;"></p>
</div>
<div class="login-row">
<div class="rem-paswd">
<input type="checkbox" name="remember_me" <?php if ($rme == 'On') { ?>checked<?php } ?>>
<label class="remember">Remember me</label>
</div>
<div class="forget-password">
<a href="<?php echo base_url(); ?>admin/forgot-password">Forgot Password?</a>
</div>
</div>
<div class="login-row">
<button type="submit" class="common-btn" onclick="validate_login_form()">Login</button>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function hide_all_login_errors() {
$('#email_error').hide();
$('#password_error').hide();
}
function celanup_login_form() {
$('#email').val('');
$('#passsword').val('');
$('#invalid_error').html('');
}
function validate_login_form() {
hide_all_login_errors();
var errArr = new Array();
var lemail = $('#email').val().trim();
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (lemail == '') {
errArr.push('email_Sep@Str_Please enter your email address.');
} else if (!regex.test(lemail)) {
errArr.push('email_Sep@Str_Please enter a valid email address.');
}
var lpwd = $('#password').val().trim();
if (lpwd == '') {
errArr.push('password_Sep@Str_Please enter your password.');
}
if (errArr.length > 0) {
for (i = 0; i < errArr.length; i++) {
var resArr = errArr[i].split("_Sep@Str_");
$("#" + resArr[0] + "_error").html(resArr[1]);;
$("#" + resArr[0] + "_error").show();
}
var xxxVal = errArr[0].split('_Sep@Str_');
$('#' + xxxVal[0]).focus();
return false;
} else {
$('#loginform').submit();
}
}
$('#loginform').submit(function(e) {
e.preventDefault();
var formData = new FormData($("#loginform")[0]);
$.ajax({
url: '<?php echo base_url(); ?>Admin/admin_login',
dataType: 'json',
type: 'POST',
data: formData,
contentType: false,
processData: false,
success: function(response) {
if (response == '1') {
window.location.href = "<?php echo base_url(); ?>admin/dashboard";
} else if (response == '0') {
$('#invalid_error').html("Invalid email or password.");
}
}
});
});
</script>