Skip to content

Commit

Permalink
Working on login system
Browse files Browse the repository at this point in the history
  • Loading branch information
zigazajc007 committed Apr 17, 2023
1 parent 30d62aa commit 91758c8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions website/check_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
return;
}

$_SESSION["msg"] = "";
unset($_SESSION["msg"]);
$_SESSION["username"] = $_POST['username'];
header("Location: panel.php");
header("Location: index.php");
?>
26 changes: 17 additions & 9 deletions website/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
include_once "Settings.php";
include_once "Utils.php";

session_start();

$ban_count = Utils::getRowCount('adminbans_banned_players');
$mute_count = Utils::getRowCount('adminbans_muted_players');
$warn_count = Utils::getRowCount('adminbans_warned_players');
Expand Down Expand Up @@ -60,15 +62,21 @@
</span>
</div>
</div>
<?php }else{ ?>
<!--
<div class="hidden flex-1 flex items-center justify-center px-2 lg:ml-6 lg:flex lg:justify-end">
<div id="login-nav" class="flex-shrink-0">
<a href="panel.php" class="primaryButton px-3 py-2 rounded-md text-sm font-medium">Log in</a>
</div>
</div>
-->
<?php } ?>
<?php }else{
if(isset($_SESSION["username"])){ ?>
<div class="hidden flex-1 flex items-center justify-center px-2 lg:ml-6 lg:flex lg:justify-end">
<div class="flex-shrink-0">
<a href="logout.php" class="tertiaryColor px-3 py-2 rounded-md text-sm font-medium">Log out</a>
</div>
</div>
<?php }else{ ?>
<div class="hidden flex-1 flex items-center justify-center px-2 lg:ml-6 lg:flex lg:justify-end">
<div class="flex-shrink-0">
<a href="login.php" class="primaryButton px-3 py-2 rounded-md text-sm font-medium">Log in</a>
</div>
</div>
<?php }
} ?>
<div class="flex items-center lg:hidden">
<button id="menu-toggle-btn" type="button" class="main-menu-toggle-btn inline-flex items-center justify-center p-2 rounded-md focus:outline-none" aria-controls="mobile-menu" aria-expanded="false">
<span class="sr-only">Open main menu</span>
Expand Down
3 changes: 3 additions & 0 deletions website/js/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
document.getElementById('dialog-button').addEventListener('click', () => {
document.getElementById('dialog').style.display = 'none';
});
15 changes: 8 additions & 7 deletions website/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
session_start();

if(isset($_SESSION["username"])){
header("Location: panel.php");
header("Location: index.php");
return;
}

Expand Down Expand Up @@ -72,7 +72,7 @@
</div>
</div>

<div id="dialog" class="hidden h-screen w-full fixed left-0 top-0 flex justify-center items-center z-10 inset-0 overflow-y-auto" aria-labelledby="dialog-title" role="dialog" aria-modal="true">
<div id="dialog" class="<?php if(!isset($_SESSION["msg"])){ echo "hidden"; } ?> h-screen w-full fixed left-0 top-0 flex justify-center items-center z-10 inset-0 overflow-y-auto" aria-labelledby="dialog-title" role="dialog" aria-modal="true">
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" aria-hidden="true"></div>
<span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
<div class="secondaryBackgroundColor inline-block align-bottom rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all m-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6">
Expand All @@ -83,23 +83,24 @@
</svg>
</div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="tertiaryColor text-lg leading-6 font-medium" id="dialog-title"></h3>
<h3 class="tertiaryColor text-lg leading-6 font-medium" id="dialog-title">Error</h3>
<div class="mt-2">
<p class="secondaryColor text-sm" id="dialog-text"></p>
<p class="secondaryColor text-sm" id="dialog-text"><?php if(isset($_SESSION["msg"])){ echo $_SESSION["msg"]; } ?></p>
</div>
</div>
</div>
<div class="mt-5 sm:mt-4 sm:ml-10 sm:pl-4 sm:flex">
<button id="dialog-button" type="button" class="dangerButton inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium focus:outline-none sm:w-auto sm:text-sm">
Okay
</button>
<button id="dialog-button-cancel" type="button" class="cancelButton mt-2 w-full inline-flex justify-center rounded-md border px-4 py-2 text-base font-medium shadow-sm focus:outline-none sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm">
Cancel
</button>
</div>
</div>
</div>

<?php
unset($_SESSION["msg"]);
?>

<script type="module" src="js/login.js"></script>
</body>
</html>
3 changes: 0 additions & 3 deletions website/check_logout.php → website/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@
session_start();
session_unset();
session_destroy();
session_write_close();
setcookie(session_name(),'',0,'/');
session_regenerate_id(true);
header("Location: index.php");
?>

0 comments on commit 91758c8

Please sign in to comment.