Transfer to git
This commit is contained in:
53
includes/register.inc.php
Normal file
53
includes/register.inc.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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 "register_model.inc.php";
|
||||
require_once "register_view.inc.php";
|
||||
require_once "register_contr.inc.php";
|
||||
|
||||
// Error handlers
|
||||
$errors = [];
|
||||
if (isEmpty($inputs)) {
|
||||
$errors = ["null_field" => "Form contains blank characters."];
|
||||
}
|
||||
if (username_taken($pdo, $inputs["username"])) {
|
||||
$errors = ["username_taken" => "Username alredy taken"];
|
||||
}
|
||||
|
||||
require_once "config_session.inc.php";
|
||||
|
||||
if ($errors) {
|
||||
$_SESSION["errors"] = $errors;
|
||||
|
||||
// Send back form
|
||||
$entered_data = [
|
||||
"username" => $inputs["username"]
|
||||
];
|
||||
|
||||
$_SESSION["entered_register_data"] = $entered_data;
|
||||
|
||||
header("Location: ../chat.php");
|
||||
$inputs = null;
|
||||
die();
|
||||
}
|
||||
|
||||
user_register($pdo, $inputs["username"], $inputs["pwd"]);
|
||||
|
||||
header("Location: ../chat.php");
|
||||
$inputs = null;
|
||||
die();
|
||||
} catch (PDOException $e) {
|
||||
echo "An error has ocurred: " . $e->getMessage();
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
echo "Wrong request type, please check your request.";
|
||||
exit();
|
||||
}
|
||||
Reference in New Issue
Block a user