php jede menge

This commit is contained in:
Peter Hoppe
2022-12-16 15:54:13 +01:00
parent accf248e3c
commit 147fd66fff
10 changed files with 437 additions and 116 deletions

View File

@ -8,28 +8,20 @@ header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers
session_start();
require __DIR__ . '/classes/Database.php';
require __DIR__ . '/classes/lib.php';
$db_connection = new Database();
$conn = $db_connection->dbConnection();
function msg($success, $status, $message, $extra = [])
{
return array_merge([
'success' => $success,
'status' => $status,
'message' => $message
], $extra);
}
// DATA FORM REQUEST
$data = json_decode(file_get_contents("php://input"));
$returnData = [];
if ($_SERVER["REQUEST_METHOD"] != "POST") :
$returnData = msg(0, 404, 'Page Not Found!');
$returnData = new CMsg(0);
if ($_SERVER["REQUEST_METHOD"] != "POST")
{
$returnData = new CMsg(0, 404, 'Page Not Found!');
}
elseif (
!isset($data->vorname)
!isset($data->qr_id)
|| !isset($data->nachname)
|| !isset($data->email)
|| !isset($data->password)
@ -40,7 +32,7 @@ elseif (
) :
$fields = ['fields' => ['vorname', 'nachname', 'email', 'password']];
$returnData = msg(0, 422, 'Please Fill in all Required Fields!', $fields);
$returnData = new CMsg(0, 422, 'Please Fill in all Required Fields!', $fields);
// IF THERE ARE NO EMPTY FIELDS THEN-
else :
@ -53,10 +45,10 @@ else :
$returnData = msg(0, 422, 'Invalid Email Address!');
elseif (strlen($password) < 8) :
$returnData = msg(0, 422, 'Your password must be at least 8 characters long!');
$returnData = new CMsg(0, 422, 'Your password must be at least 8 characters long!');
elseif (strlen($nachname) < 3) :
$returnData = msg(0, 422, 'Your name must be at least 3 characters long!');
$returnData = new CMsg(0, 422, 'Your name must be at least 3 characters long!');
else :
try {
@ -67,7 +59,7 @@ else :
$check_email_stmt->execute();
if ($check_email_stmt->rowCount()) :
$returnData = msg(0, 422, 'This E-mail already in use!');
$returnData = new CMsg(0, 422, 'This E-mail already in use!');
else :
$insert_query = "INSERT INTO `users`(`vorname`,`nachname`,`email`,`password`) VALUES(:vorname,:nachname,:email,:password)";
@ -82,13 +74,14 @@ else :
$insert_stmt->execute();
$returnData = msg(1, 201, 'You have successfully registered.');
$returnData = new CMsg(1, 201, 'You have successfully registered.');
endif;
} catch (PDOException $e) {
$returnData = msg(0, 500, $e->getMessage());
$returnData = new CMsg(0, 500, $e->getMessage());
}
endif;
endif;
echo json_encode($returnData);
echo $returnData->jsonarray();
?>