Confirm Register
This commit is contained in:
@@ -34,6 +34,28 @@ class User implements JsonSerializable
|
||||
$this->postCount = $postCount;
|
||||
}
|
||||
|
||||
private static function getByConfirmCode(string $code): User
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"SELECT
|
||||
b.id, b.benutzer, b.status, b.email, b.image, b.isadmin, b.zeitstempel,
|
||||
(SELECT COUNT(*) FROM egb_gaestebuch WHERE benutzer_id = b.id) as postCount
|
||||
FROM
|
||||
egb_benutzer AS b
|
||||
WHERE
|
||||
confirmationcode = :COD"
|
||||
);
|
||||
$stmt->bindValue(":COD", $code);
|
||||
$stmt->execute();
|
||||
$data = $stmt->fetch();
|
||||
|
||||
if (!$data) throw new Exception("NotFound");
|
||||
|
||||
return new User($data["id"], $data["benutzer"], $data["status"], $data["email"], $data["zeitstempel"], $data["image"], $data["isadmin"] === 1, $data["postCount"]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Statics
|
||||
*/
|
||||
@@ -189,7 +211,21 @@ class User implements JsonSerializable
|
||||
|
||||
public static function confirm(string $confirmCode): bool
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = User::getByConfirmCode($confirmCode);
|
||||
|
||||
$stmt = $db->prepare(
|
||||
"UPDATE
|
||||
egb_benutzer
|
||||
SET
|
||||
status = 1,
|
||||
confirmationcode = NULL
|
||||
WHERE id = :UID"
|
||||
);
|
||||
$stmt->bindValue(":UID", $user->getID());
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user