Register endpoint
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user