<?php
include('header.php');
?>

<!-- start main -->
<section class="user-form-part">
	<div class="container">
		<div class="row justify-content-center">
			<div class="col-12 col-sm-10 col-md-8 col-lg-6 col-xl-5 mb-4">
				<div class="user-form-card">
					<div class="user-form-title">
						<h2>welcome!</h2>
						<p>Use your credentials to access</p>
					</div>
					<form class="user-form" method="POST" id="loginform" action="<?=base_url('login/verify');?>">
						<div class="form-group"><input type="text" id="username" name="username"  class="form-control" placeholder="Enter Email/Mobile number"></div>
						<div class="input-group mb-3">
                            <input type="password" id="password" name="password" class="form-control" placeholder="Enter your password">
                            <button class="bg-theme-color text-white rounded px-3" type="button" onclick="if($('#password').attr('type')=='password'){$('#password').attr('type','text');}else{$('#password').attr('type','password');}$('#eye').toggleClass('fa-eye');"><i id="eye" class="fa fa-eye-slash"></i></button>
                        </div>
                        <style>.fa-eye:before { content: "\f06e"; }</style>
						<div class="form-button"><button type="submit">login</button>
							<p>Forgot your password?<a href="<?=base_url('forget_password');?>">reset here</a></p>
						</div>
					</form>
				</div>
				<div class="user-form-remind">
					<p>Don't have any account?<a href="<?=base_url('register');?>">register here</a></p>
				</div>
			</div>
		</div>
	</div>
</section>
<!-- end main -->

<?php
include('footer.php');
?>

<? // login verification process;?>
<script>
    $(document).ready(function(){
        $('#loginform').submit(function(){
            var username = $("#username").val();
	        var password = $("#password").val();
	        $.ajax({
	            type: "POST",
	            url: "<?=base_url('login/verify');?>",
	            data: {
	                cust_email: username,
	                cust_password: password
	            },
	            success: function(data) {
	                var obj = JSON.parse(data);
	                if(obj.log == 0){
                        sweetalert('warning', obj.error);
                    }
                    if(obj.log == 1){
                        sweetalert('success', obj.succ);
                        setTimeout(function(){ window.location='<?=base_url('profile');?>';}, 2500);
                    }
	            }
	        });
            return false;
        });
    });

</script>
<? // login verification process;?>