aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Models/User.php
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-21 21:49:57 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-21 21:49:57 +0100
commitf60a390f5c51039fd1efc1df9a6a7f3864ce0062 (patch)
tree9ec829dd92a93a79a2047494d07c95b7c0197389 /src/app/Models/User.php
parentbc54c8c31e7f50a7a365f9b4d22fe8c74a29f61a (diff)
downloadcamagru-f60a390f5c51039fd1efc1df9a6a7f3864ce0062.tar.gz
camagru-f60a390f5c51039fd1efc1df9a6a7f3864ce0062.zip
Add profile page for editing username, email, password, and notifications
Diffstat (limited to 'src/app/Models/User.php')
-rw-r--r--src/app/Models/User.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/app/Models/User.php b/src/app/Models/User.php
index d4c5c88..7cfbf3c 100644
--- a/src/app/Models/User.php
+++ b/src/app/Models/User.php
@@ -115,4 +115,30 @@ class User
$row = $stmt->fetch();
return $row ? $row['verification_token'] : null;
}
+
+ public function updateUsername(int $id, string $username): void
+ {
+ $stmt = $this->pdo->prepare('UPDATE users SET username = :username WHERE id = :id');
+ $stmt->execute(['username' => $username, 'id' => $id]);
+ }
+
+ /**
+ * Change email and require re-verification.
+ * Returns the new verification token so the caller can send a verification email.
+ */
+ public function updateEmail(int $id, string $email): string
+ {
+ $token = bin2hex(random_bytes(32));
+ $stmt = $this->pdo->prepare(
+ 'UPDATE users SET email = :email, is_verified = FALSE, verification_token = :token WHERE id = :id'
+ );
+ $stmt->execute(['email' => $email, 'token' => $token, 'id' => $id]);
+ return $token;
+ }
+
+ public function updateNotifyComments(int $id, bool $notify): void
+ {
+ $stmt = $this->pdo->prepare('UPDATE users SET notify_comments = :notify WHERE id = :id');
+ $stmt->execute(['notify' => $notify ? 1 : 0, 'id' => $id]);
+ }
}