forked from laysense/laysense.cn
Fix CMS login and restore PAGEPAN feature icons
This commit is contained in:
+19
-11
@@ -168,28 +168,36 @@ final class Repository
|
||||
return $this->one('SELECT id, email, password_hash FROM users WHERE id = ?', [$id]);
|
||||
}
|
||||
|
||||
public function recordLoginAttempt(string $address): bool
|
||||
public function changePassword(array $user, string $newHash): bool
|
||||
{
|
||||
return Database::write(function (PDO $pdo) use ($address): bool {
|
||||
$now = time();
|
||||
$query = $this->pdo->prepare('UPDATE users SET password_hash = ? WHERE id = ? AND password_hash = ?');
|
||||
$query->execute([$newHash, $user['id'], $user['password_hash']]);
|
||||
|
||||
return $query->rowCount() === 1;
|
||||
}
|
||||
|
||||
public function recordFailedLogin(string $address): int
|
||||
{
|
||||
$now = time();
|
||||
$current = $this->one('SELECT attempts, expires_at FROM login_attempts WHERE address = ?', [$address]);
|
||||
if ($current && $current['attempts'] >= 12 && $current['expires_at'] > $now) {
|
||||
return $current['expires_at'] - $now;
|
||||
}
|
||||
|
||||
return Database::write(function (PDO $pdo) use ($address, $now): int {
|
||||
$pdo->prepare('DELETE FROM login_attempts WHERE expires_at <= ?')->execute([$now]);
|
||||
$current = $this->one('SELECT attempts FROM login_attempts WHERE address = ?', [$address]);
|
||||
$current = $this->one('SELECT attempts, expires_at FROM login_attempts WHERE address = ?', [$address]);
|
||||
if ($current && $current['attempts'] >= 12) {
|
||||
return false;
|
||||
return $current['expires_at'] - $now;
|
||||
}
|
||||
$query = $pdo->prepare('INSERT INTO login_attempts (address, attempts, expires_at) VALUES (?, 1, ?)
|
||||
ON CONFLICT (address) DO UPDATE SET attempts = attempts + 1');
|
||||
$query->execute([$address, $now + 900]);
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
public function clearLoginAttempts(string $address): void
|
||||
{
|
||||
$this->pdo->prepare('DELETE FROM login_attempts WHERE address = ?')->execute([$address]);
|
||||
}
|
||||
|
||||
private function one(string $sql, array $args): ?array
|
||||
{
|
||||
$query = $this->pdo->prepare($sql);
|
||||
|
||||
Reference in New Issue
Block a user