mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-06-24 02:36:16 +00:00
Updating Login to new AJAX system
This commit is contained in:
parent
10fbfc2067
commit
a5212b1d11
6 changed files with 142 additions and 84 deletions
|
@ -43,7 +43,17 @@
|
|||
echo "<h3>Invite Codes</h3>";
|
||||
$token_request = mysqli_query($conn, "SELECT * FROM tokens WHERE used = 0");
|
||||
while ($token = mysqli_fetch_array($token_request)) {
|
||||
echo "<p>".$token['code']."</p>";
|
||||
?>
|
||||
<!-- Button that's displayed with the invite code -->
|
||||
<button onclick='copyCode()' class='btn btn-neutral'><?php echo $token['code']; ?></button>
|
||||
<!-- Copy code on click -->
|
||||
<script>
|
||||
function copyCode() {
|
||||
navigator.clipboard.writeText("<?php echo $token['code']; ?>");
|
||||
sniffleAdd("Info", "Invite code has been copied!", "var(--green)", "<?php echo $root_dir; ?>assets/icons/clipboard-text.svg");
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -33,81 +33,13 @@
|
|||
include "../ui/required.php";
|
||||
include "../ui/nav.php";
|
||||
|
||||
// Initialize the session
|
||||
session_start();
|
||||
|
||||
// Check if the user is already logged in, if yes then redirect him to welcome page
|
||||
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){
|
||||
$success = "You're already logged in! No need to try this again";
|
||||
}
|
||||
|
||||
if (isset($_POST['login'])) {
|
||||
// Checking if Username is empty
|
||||
if (empty(trim($_POST["username"]))) {
|
||||
$error = "Who are you?";
|
||||
} else {
|
||||
$username = trim($_POST["username"]);
|
||||
}
|
||||
|
||||
// Check if Password is empty
|
||||
if (empty(trim($_POST["password"]))) {
|
||||
$error = "Pls enter super duper secrete password";
|
||||
} else {
|
||||
$password = trim($_POST["password"]);
|
||||
}
|
||||
|
||||
// Check if no errors occured
|
||||
if (empty($error)) {
|
||||
// Prepare so SQL doesnt get spooked
|
||||
$sql = "SELECT id, username, password FROM users WHERE username = ?";
|
||||
|
||||
if ($stmt = mysqli_prepare($conn, $sql)) {
|
||||
// Bind dis shit
|
||||
mysqli_stmt_bind_param($stmt, "s", $param_username);
|
||||
|
||||
// Set parameters
|
||||
$param_username = $username;
|
||||
|
||||
// Attempt to execute the prepared statement
|
||||
if (mysqli_stmt_execute($stmt)) {
|
||||
// Store result
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
// Check if username exists, if yes then verify password
|
||||
if (mysqli_stmt_num_rows($stmt) == 1) {
|
||||
// Bind result variables
|
||||
mysqli_stmt_bind_result($stmt, $id, $username, $hashed_password);
|
||||
if (mysqli_stmt_fetch($stmt)) {
|
||||
if (password_verify($password, $hashed_password)) {
|
||||
// Password is correct, so start a new session
|
||||
session_start();
|
||||
|
||||
// Store data in session variables
|
||||
$_SESSION["loggedin"] = true;
|
||||
$_SESSION["id"] = $id;
|
||||
$_SESSION["username"] = $username;
|
||||
|
||||
// let the user know
|
||||
$success = "Yupee! You are now logged in";
|
||||
header("Location:https://superdupersecteteuploadtest.fluffybean.gay/index.php?login=success");
|
||||
} else {
|
||||
$error = "Username or Password sus, please try again :3";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$error = "Username or Password sus, please try again :3";
|
||||
}
|
||||
} else {
|
||||
$error = "Sowwy, something went wrong on our end :c";
|
||||
}
|
||||
|
||||
// Close statement
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
}
|
||||
|
||||
// Close connection
|
||||
mysqli_close($conn);
|
||||
?>
|
||||
<script>
|
||||
sniffleAdd('Whatcha doing here?', 'You are already logged in! No need to try again', 'var(--black)', '<?php echo $root_dir; ?>assets/icons/warning.svg');
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
|
@ -115,15 +47,29 @@
|
|||
<h2>Login</h2>
|
||||
<p>Passwords are important to keep safe. Don't tell anyone your password, not even Fluffy!</p>
|
||||
<br>
|
||||
<form method="POST" action="login.php" enctype="multipart/form-data">
|
||||
<input class="btn btn-neutral" type="text" name="username" placeholder="Username">
|
||||
<input class="btn btn-neutral" type="password" name="password" placeholder="Password">
|
||||
<form id="loginSubmit" method="POST" enctype="multipart/form-data">
|
||||
<input id="loginUsername" class="btn btn-neutral" type="text" name="username" placeholder="Username">
|
||||
<input id="loginPassword" class="btn btn-neutral" type="password" name="password" placeholder="Password">
|
||||
<br>
|
||||
<button class="btn btn-good" type="submit" name="login"><img class="svg" src="../assets/icons/sign-in.svg">Login</button>
|
||||
<button id="loginSubmit" class="btn btn-good" type="submit" name="login"><img class="svg" src="../assets/icons/sign-in.svg">Login</button>
|
||||
</form>
|
||||
<a class='btn btn-neutral' href='https://superdupersecteteuploadtest.fluffybean.gay/account/signup.php'><img class="svg" src="../assets/icons/sign-in.svg">Need an account? Sign up!</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$("#loginSubmit").submit(function(event) {
|
||||
event.preventDefault();
|
||||
var username = $("#loginUsername").val();
|
||||
var password = $("#loginPassword").val();
|
||||
var submit = $("#loginSubmit").val();
|
||||
$("#sniffle").load("../app/account/login.php", {
|
||||
username: username,
|
||||
password: password,
|
||||
submit: submit
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php include "../ui/footer.php"; ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue