Public badge for restored photos and commenter link retrieval/regeneration

This commit is contained in:
Alex Assistant
2026-02-20 15:13:46 +03:00
parent 9207c739fc
commit 0995989b56
5 changed files with 37 additions and 5 deletions
+11 -2
View File
@@ -100,8 +100,8 @@ function commenterCreate(string $displayName): array
{
$token = bin2hex(random_bytes(16));
$hash = hash('sha256', $token);
$st = db()->prepare('INSERT INTO comment_users(display_name, token_hash, is_active) VALUES (:n,:h,1)');
$st->execute(['n' => $displayName, 'h' => $hash]);
$st = db()->prepare('INSERT INTO comment_users(display_name, token_hash, token_plain, is_active) VALUES (:n,:h,:p,1)');
$st->execute(['n' => $displayName, 'h' => $hash, 'p' => $token]);
return [
'id' => (int)db()->lastInsertId(),
@@ -121,6 +121,15 @@ function commenterDelete(int $id): void
$st->execute(['id' => $id]);
}
function commenterRegenerateToken(int $id): string
{
$token = bin2hex(random_bytes(16));
$hash = hash('sha256', $token);
$st = db()->prepare('UPDATE comment_users SET token_hash=:h, token_plain=:p WHERE id=:id');
$st->execute(['h' => $hash, 'p' => $token, 'id' => $id]);
return $token;
}
function commentsByPhoto(int $photoId): array
{
$sql = 'SELECT c.*, u.display_name