Register endpoint

This commit is contained in:
2024-07-22 02:21:30 +02:00
parent d94c342bd6
commit af588ab174
9 changed files with 192 additions and 43 deletions
+33
View File
@@ -8,6 +8,8 @@ use DateTime;
use Khofmann\Database\Database;
use Config\Config;
use JsonSerializable;
use Khofmann\GUID\GUID;
use PDOException;
class User implements JsonSerializable
{
@@ -153,6 +155,37 @@ class User implements JsonSerializable
}
}
public static function create(string $username, string $email, string $password)
{
$db = Database::getInstance();
$guid = GUID::v4();
$stmt = $db->prepare(
"INSERT INTO
egb_benutzer(benutzer, passwort, email, confirmationcode)
VALUES(:USR, :PAS, :EMA, :COD)"
);
$stmt->bindValue(":USR", $username);
$stmt->bindValue(":PAS", password_hash($password, PASSWORD_DEFAULT));
$stmt->bindValue(":EMA", $email);
$stmt->bindValue(":COD", $guid);
try {
$stmt->execute();
mail(
$email,
"Account activation GuestBookDB",
"Hello $username. To activate your account, visit https://khofmann.userpage.fu-berlin.de/phpCourse/exam/confirm?c=$guid"
);
return true;
} catch (Exception $err) {
if ($err->getCode() === "23000") throw new Exception("Duplicate");
throw $err;
}
}
/*
* Members
*/