Endpoints
This commit is contained in:
@@ -177,7 +177,7 @@ class User implements JsonSerializable
|
||||
}
|
||||
}
|
||||
|
||||
public static function create(string $username, string $email, string $password): bool
|
||||
public static function create(string $username, string $email, string $password): User
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$guid = GUID::v4();
|
||||
@@ -192,6 +192,8 @@ class User implements JsonSerializable
|
||||
$stmt->bindValue(":EMA", $email);
|
||||
$stmt->bindValue(":COD", $guid);
|
||||
|
||||
$user = User::getByID($db->lastInsertId());
|
||||
|
||||
try {
|
||||
$stmt->execute();
|
||||
|
||||
@@ -201,7 +203,7 @@ class User implements JsonSerializable
|
||||
"Hello $username. To activate your account, visit https://khofmann.userpage.fu-berlin.de/phpCourse/exam/confirm?c=$guid"
|
||||
);
|
||||
|
||||
return true;
|
||||
return $user;
|
||||
} catch (Exception $err) {
|
||||
if ($err->getCode() === "23000") throw new Exception("Duplicate");
|
||||
|
||||
@@ -267,7 +269,7 @@ class User implements JsonSerializable
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
public function update(?string $username, ?string $password, $image = null): bool
|
||||
public function update(?string $username, ?string $password, $image = null): User
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
@@ -299,15 +301,16 @@ class User implements JsonSerializable
|
||||
}
|
||||
if ($error) throw new Exception("FailedImage");
|
||||
|
||||
return true;
|
||||
return User::getByID($this->id);
|
||||
}
|
||||
|
||||
public function delete(): bool
|
||||
public function delete(): User
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$stmt = $db->prepare("DELETE FROM egb_benutzer WHERE id = :ID");
|
||||
$stmt->bindValue(":ID", $this->id);
|
||||
return $stmt->execute();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user