Better Errors
This commit is contained in:
@@ -8,6 +8,7 @@ use DateTime;
|
||||
use Khofmann\Database\Database;
|
||||
use Config\Config;
|
||||
use JsonSerializable;
|
||||
use Khofmann\ApiError\ApiError;
|
||||
use Khofmann\GUID\GUID;
|
||||
use PDOException;
|
||||
|
||||
@@ -192,11 +193,11 @@ class User implements JsonSerializable
|
||||
$stmt->bindValue(":EMA", $email);
|
||||
$stmt->bindValue(":COD", $guid);
|
||||
|
||||
$user = User::getByID($db->lastInsertId());
|
||||
|
||||
try {
|
||||
$stmt->execute();
|
||||
|
||||
$user = User::getByID($db->lastInsertId());
|
||||
|
||||
mail(
|
||||
$email,
|
||||
"Account activation GuestBookDB",
|
||||
@@ -211,7 +212,7 @@ class User implements JsonSerializable
|
||||
}
|
||||
}
|
||||
|
||||
public static function confirm(string $confirmCode): bool
|
||||
public static function confirm(string $confirmCode): User
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
$user = User::getByConfirmCode($confirmCode);
|
||||
@@ -225,7 +226,7 @@ class User implements JsonSerializable
|
||||
WHERE id = :UID"
|
||||
);
|
||||
$stmt->bindValue(":UID", $user->getID());
|
||||
return $stmt->execute();
|
||||
return User::getByID($user->getID());
|
||||
}
|
||||
|
||||
public static function list(int $page, int $limit)
|
||||
@@ -273,22 +274,28 @@ class User implements JsonSerializable
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$error = false;
|
||||
$failed = [];
|
||||
if (!empty($username)) {
|
||||
$stmt = $db->prepare("UPDATE egb_benutzer SET benutzer = :USR WHERE id = :ID");
|
||||
$stmt->bindValue(":USR", $username);
|
||||
$stmt->bindValue(":ID", $this->id);
|
||||
$error = !$stmt->execute();
|
||||
try {
|
||||
if (!$stmt->execute()) array_push($failed, "username");
|
||||
} catch (Exception $e) {
|
||||
array_push($failed, "username");
|
||||
}
|
||||
}
|
||||
if ($error) throw new Exception("FailedUsername");
|
||||
|
||||
if (!empty($password)) {
|
||||
$stmt = $db->prepare("UPDATE egb_benutzer SET passwort = :PAS WHERE id = :ID");
|
||||
$stmt->bindValue(":PAS", password_hash($password, PASSWORD_DEFAULT));
|
||||
$stmt->bindValue(":ID", $this->id);
|
||||
$error = !$stmt->execute();
|
||||
try {
|
||||
if (!$stmt->execute()) array_push($failed, "password");
|
||||
} catch (Exception $e) {
|
||||
array_push($failed, "password");
|
||||
}
|
||||
}
|
||||
if ($error) throw new Exception("FailedPassword");
|
||||
|
||||
if (!empty($image)) {
|
||||
$destinationFilename = sprintf('%s.%s', uniqid(), $image->getExtension());
|
||||
@@ -297,9 +304,13 @@ class User implements JsonSerializable
|
||||
$stmt = $db->prepare("UPDATE egb_benutzer SET image = :IMG WHERE id = :ID");
|
||||
$stmt->bindValue(":IMG", $destinationFilename);
|
||||
$stmt->bindValue(":ID", $this->id);
|
||||
$error = !$stmt->execute();
|
||||
try {
|
||||
if (!$stmt->execute()) array_push($failed, "image");
|
||||
} catch (Exception $e) {
|
||||
array_push($failed, "image");
|
||||
}
|
||||
}
|
||||
if ($error) throw new Exception("FailedImage");
|
||||
if (count($failed) > 0) throw ApiError::failedUpdate($failed);
|
||||
|
||||
return User::getByID($this->id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user