-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
110 lines (98 loc) · 3.55 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
session_start();
if(isset($_SESSION['userid']) && $_SESSION['userid'] > 0){
header("Location:./");
exit;
}
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/script.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<style>
h1{
display:inline;
}
.container{
width:35%;
display:flex;
flex-direction:column;
}
body{
margin-top: 100px;
height:80vh;
}
input{
display:inline;
}
</style>
</head>
<body>
<div class="container my-4">
<h3 class="text-center">THE SUPERMART PANEL</h3>
<form action="" id="login-form">
<div class="mb-3 col-md-17 ">
<label for="username" class="form-label">username</label>
<input type="text" id="username" autofocus name="username" class="form-control" required>
</div>
<div class="mb-3 col-md-17">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<button class="btn btn-primary">Log in</button>
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
</body>
<script>
$(function(){
$('#login-form').submit(function(e){
e.preventDefault();
$('.pop_msg').remove()
var _this = $(this)
var _el = $('<div>')
_el.addClass('pop_msg')
_this.find('button').attr('disabled',true)
_this.find('button[type="submit"]').text('Loging in...')
$.ajax({
url:'sessions.php?a=login',
method:'POST',
data:$(this).serialize(),
dataType:'JSON',
error:err=>{
console.log(err)
_el.addClass('alert alert-danger')
_el.text("An error occurred.")
_this.prepend(_el)
_el.show('slow')
_this.find('button').attr('disabled',false)
_this.find('button[type="submit"]').text('Save')
},
success:function(resp){
if(resp.status == 'success'){
_el.addClass('alert alert-success')
setTimeout(() => {
location.replace('./');
}, 2000);
}else{
_el.addClass('alert alert-danger')
}
_el.text(resp.msg)
_el.hide()
_this.prepend(_el)
_el.show('slow')
_this.find('button').attr('disabled',false)
_this.find('button[type="submit"]').text('Save')
}
})
})
})
</script>
</html>