add superadmin dashboard. subscriptions

This commit is contained in:
root
2026-01-13 20:03:16 +03:00
parent 3c24c250e5
commit edb4df7e37
36 changed files with 3329 additions and 100 deletions
+78 -1
View File
@@ -24,7 +24,13 @@ class UserModel extends Model
// Поля для верификации email
'verification_token',
'email_verified',
'verified_at'
'verified_at',
// Поля для восстановления пароля
'reset_token',
'reset_expires_at',
//системная роль
'system_role',
'status',
];
// Dates
@@ -44,4 +50,75 @@ class UserModel extends Model
}
return $data;
}
/**
* Генерация токена для сброса пароля
*
* @param int $userId ID пользователя
* @param int $expiresInHours Срок действия токена в часах (по умолчанию 24 часа)
* @return string Сгенерированный токен
*/
public function generateResetToken(int $userId, int $expiresInHours = 24): string
{
$token = bin2hex(random_bytes(32));
$expiresAt = date('Y-m-d H:i:s', strtotime("+{$expiresInHours} hours"));
$this->update($userId, [
'reset_token' => $token,
'reset_expires_at' => $expiresAt,
]);
return $token;
}
/**
* Проверка токена сброса пароля
*
* @param string $token Токен сброса
* @return array|null Данные пользователя или null если токен недействителен
*/
public function verifyResetToken(string $token): ?array
{
$user = $this->where('reset_token', $token)->first();
if (!$user) {
return null;
}
// Проверяем срок действия токена
if (empty($user['reset_expires_at'])) {
return null;
}
if (strtotime($user['reset_expires_at']) < time()) {
return null;
}
return $user;
}
/**
* Очистка токена сброса пароля
*
* @param int $userId ID пользователя
* @return bool
*/
public function clearResetToken(int $userId): bool
{
return $this->update($userId, [
'reset_token' => null,
'reset_expires_at' => null,
]);
}
/**
* Поиск пользователя по email
*
* @param string $email Email адрес
* @return array|null
*/
public function findByEmail(string $email): ?array
{
return $this->where('email', $email)->first();
}
}