aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/Models')
-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]);
+ }
}