added login/logout functionality
This commit is contained in:
parent
ebc0007069
commit
02edcd600b
4 changed files with 78 additions and 15 deletions
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//frontend data
|
//frontend data
|
||||||
define('SITE_URL', 'http://127.0.0.1:3000/');
|
define('SITE_URL', 'http://127.0.0.1:3500/');
|
||||||
define('MANAGMENT_IMG_PATH', SITE_URL.'images/admin/management/');
|
define('MANAGMENT_IMG_PATH', SITE_URL.'images/admin/management/');
|
||||||
define('ROOM_IMG_PATH', SITE_URL.'images/admin/rooms/');
|
define('ROOM_IMG_PATH', SITE_URL.'images/admin/rooms/');
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,22 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="../contact.php">Contact</a>
|
<a class="nav-link" href="../contact.php">Contact</a>
|
||||||
</li>
|
</li>
|
||||||
|
<?php
|
||||||
|
if(isset($_SESSION['login']) && $_SESSION['login'] == true){
|
||||||
|
echo <<<data
|
||||||
|
<div class="btn-group">
|
||||||
|
<button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" data-bs-display="static" aria-expanded="false" style="outline: none; box-shadow: none;">
|
||||||
|
$_SESSION[userName]
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-lg-end">
|
||||||
|
<li><a href="profile.php" class="dropdown-item">Profile</a></li>
|
||||||
|
<li><a href="user_booking.php" class="dropdown-item">Booking</a></li>
|
||||||
|
<li><a href="logout.php" class="dropdown-item">Logout</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
data;
|
||||||
|
} else{
|
||||||
|
echo <<<data
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<a class="btn btn-secondary dropdown-toggle" style="outline: none; box-shadow: none; background-color: transparent;" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">Join</a>
|
<a class="btn btn-secondary dropdown-toggle" style="outline: none; box-shadow: none; background-color: transparent;" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-expanded="false">Join</a>
|
||||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink" style="background-color: #272829;">
|
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink" style="background-color: #272829;">
|
||||||
|
@ -38,6 +54,9 @@
|
||||||
<li class="nav-item"><a class="nav-link" data-bs-toggle="modal" data-bs-target="#registerBackdrop" style="cursor: pointer;">Register</a></li>
|
<li class="nav-item"><a class="nav-link" data-bs-toggle="modal" data-bs-target="#registerBackdrop" style="cursor: pointer;">Register</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
data;
|
||||||
|
}
|
||||||
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -88,7 +107,7 @@
|
||||||
<div class="modal fade" id="loginBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
<div class="modal fade" id="loginBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<form>
|
<form id="login-form">
|
||||||
<div class="modal-header" style="border: none;">
|
<div class="modal-header" style="border: none;">
|
||||||
<button type="reset" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="reset" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -97,12 +116,12 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Email address</label>
|
<label class="form-label">Email</label>
|
||||||
<input type="email" class="form-control shadow-none">
|
<input type="text" name="email" required class="form-control shadow-none">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label">Password</label>
|
<label class="form-label">Password</label>
|
||||||
<input type="password" class="form-control shadow-none">
|
<input type="password" name="password" required class="form-control shadow-none">
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<a href="javascript: void(0)" style="font-size: 14px; color: gray;">Forgot your password?</a>
|
<a href="javascript: void(0)" style="font-size: 14px; color: gray;">Forgot your password?</a>
|
||||||
|
@ -199,6 +218,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let register_form = document.getElementById('register-form');
|
let register_form = document.getElementById('register-form');
|
||||||
|
let login_form = document.getElementById('login-form');
|
||||||
|
/*=== register ===*/
|
||||||
register_form.addEventListener('submit', (e) => {
|
register_form.addEventListener('submit', (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
@ -240,5 +261,39 @@
|
||||||
xhr.send(data);
|
xhr.send(data);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
/*=== login ===*/
|
||||||
|
login_form.addEventListener('submit', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
let data = new FormData();
|
||||||
|
data.append('email', login_form.elements['email'].value);
|
||||||
|
data.append('password', login_form.elements['password'].value);
|
||||||
|
data.append('login', '');
|
||||||
|
|
||||||
|
var myModal = document.getElementById('loginBackdrop');
|
||||||
|
var modal = bootstrap.Modal.getInstance(myModal);
|
||||||
|
modal.hide();
|
||||||
|
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.open("POST", "ajax/login_register.php", true);
|
||||||
|
|
||||||
|
xhr.onload = function(){
|
||||||
|
if(this.responseText == 'inv_email'){
|
||||||
|
alert('error', 'Wrong credentials, please try again!');
|
||||||
|
} else if(this.responseText == 'not_verified'){
|
||||||
|
alert('error', 'Please verify your email');
|
||||||
|
} else if(this.responseText == 'inactive'){
|
||||||
|
alert('error', 'Your account is suspended, please try again later!');
|
||||||
|
} else if(this.responseText == 'invalid_pass'){
|
||||||
|
alert('error', 'Wrong credentials, please try again!');
|
||||||
|
} else{
|
||||||
|
window.location = window.location.pathname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.send(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
|
@ -5,3 +5,7 @@
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||||
<link rel="shortcut icon" href="./images/logo.png" type="image/x-icon">
|
<link rel="shortcut icon" href="./images/logo.png" type="image/x-icon">
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"/><link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400..700;1,400..700&family=Righteous&display=swap" rel="stylesheet">
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"/><link href="https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400..700;1,400..700&family=Righteous&display=swap" rel="stylesheet">
|
||||||
|
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
?>
|
6
hotel_booking/logout.php
Normal file
6
hotel_booking/logout.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
require('admin/components/utils.php');
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
redirect('index.php');
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue