Transfer to git
This commit is contained in:
65
includes/login.inc.php
Normal file
65
includes/login.inc.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
|
||||
$inputs = [
|
||||
"username" => $_POST["username"],
|
||||
"pwd" => $_POST["pwd"]
|
||||
];
|
||||
|
||||
try {
|
||||
require_once "dbh.inc.php";
|
||||
require_once "login_model.inc.php";
|
||||
require_once "login_view.inc.php";
|
||||
require_once "login_contr.inc.php";
|
||||
|
||||
$errors = [];
|
||||
|
||||
if (isEmpty($inputs)) {
|
||||
$errors = ["null_field" => "Form contains blank characters."];
|
||||
}
|
||||
|
||||
if (!does_user_exist($pdo, $inputs["username"])) {
|
||||
$errors = ["incorrect_credentials" => "Incorrect credentials"];
|
||||
} else {
|
||||
if (!does_Password_match($pdo, $inputs["username"], $inputs["pwd"])){
|
||||
$errors = ["incorrect_credentials" => "Incorrect credentials"];
|
||||
}
|
||||
}
|
||||
|
||||
require_once "config_session.inc.php";
|
||||
|
||||
if ($errors) {
|
||||
|
||||
$_SESSION["errors"] = $errors;
|
||||
|
||||
// Send back form
|
||||
$entered_data = [
|
||||
"username" => $inputs["username"]
|
||||
];
|
||||
|
||||
$_SESSION["entered_login_data"] = $entered_data;
|
||||
|
||||
header("Location: ../chat.php");
|
||||
|
||||
$inputs = null;
|
||||
die();
|
||||
}
|
||||
|
||||
$_SESSION["username"] = htmlspecialchars($inputs["username"]);
|
||||
|
||||
$inputs = null;
|
||||
header("Location: ../chat.php");
|
||||
die();
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo "An error has ocurred: " . $e->getMessage();
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
echo("Wrong request type, please check your request.");
|
||||
header("Location: ../chat.php");
|
||||
exit();
|
||||
}
|
||||
Reference in New Issue
Block a user