Fix LESS import error and refactor project structure
This commit is contained in:
@@ -4,46 +4,30 @@ namespace App\Models;
|
||||
|
||||
use App\Core\Model;
|
||||
|
||||
/**
|
||||
* User - модель пользователя
|
||||
*/
|
||||
class User extends Model
|
||||
{
|
||||
protected string $table = 'users';
|
||||
protected string $primaryKey = 'user_id';
|
||||
|
||||
/**
|
||||
* Найти пользователя по email
|
||||
*/
|
||||
public function findByEmail(string $email): ?array
|
||||
{
|
||||
return $this->findWhere(['email' => $email]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверить пароль пользователя
|
||||
*/
|
||||
public function verifyPassword(string $password, string $hash): bool
|
||||
{
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Хешировать пароль
|
||||
*/
|
||||
public function hashPassword(string $password): string
|
||||
{
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Создать нового пользователя
|
||||
*/
|
||||
public function register(array $data): ?int
|
||||
{
|
||||
$config = require dirname(__DIR__, 2) . '/config/app.php';
|
||||
|
||||
// Проверяем, является ли email администраторским
|
||||
$isAdmin = in_array(strtolower($data['email']), $config['admin_emails'] ?? []);
|
||||
|
||||
return $this->create([
|
||||
@@ -52,14 +36,11 @@ class User extends Model
|
||||
'full_name' => $data['full_name'],
|
||||
'phone' => $data['phone'] ?? null,
|
||||
'city' => $data['city'] ?? null,
|
||||
'is_admin' => $isAdmin,
|
||||
'is_active' => true
|
||||
'is_admin' => $isAdmin ? 'true' : 'false',
|
||||
'is_active' => 'true'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Авторизация пользователя
|
||||
*/
|
||||
public function authenticate(string $email, string $password): ?array
|
||||
{
|
||||
$user = $this->findByEmail($email);
|
||||
@@ -76,7 +57,6 @@ class User extends Model
|
||||
return null;
|
||||
}
|
||||
|
||||
// Обновляем время последнего входа
|
||||
$this->update($user['user_id'], [
|
||||
'last_login' => date('Y-m-d H:i:s')
|
||||
]);
|
||||
@@ -84,9 +64,6 @@ class User extends Model
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить активных пользователей
|
||||
*/
|
||||
public function getActive(int $limit = 50): array
|
||||
{
|
||||
$sql = "SELECT * FROM {$this->table}
|
||||
@@ -96,9 +73,6 @@ class User extends Model
|
||||
return $this->query($sql, [$limit]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить всех пользователей с пагинацией
|
||||
*/
|
||||
public function getAllPaginated(int $limit = 50, int $offset = 0): array
|
||||
{
|
||||
$sql = "SELECT * FROM {$this->table}
|
||||
@@ -107,18 +81,12 @@ class User extends Model
|
||||
return $this->query($sql, [$limit, $offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверить существование email
|
||||
*/
|
||||
public function emailExists(string $email): bool
|
||||
{
|
||||
$user = $this->findByEmail($email);
|
||||
return $user !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обновить профиль пользователя
|
||||
*/
|
||||
public function updateProfile(int $userId, array $data): bool
|
||||
{
|
||||
$allowedFields = ['full_name', 'phone', 'city'];
|
||||
@@ -128,9 +96,6 @@ class User extends Model
|
||||
return $this->update($userId, $updateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Изменить пароль
|
||||
*/
|
||||
public function changePassword(int $userId, string $newPassword): bool
|
||||
{
|
||||
return $this->update($userId, [
|
||||
@@ -139,9 +104,6 @@ class User extends Model
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Заблокировать/разблокировать пользователя
|
||||
*/
|
||||
public function setActive(int $userId, bool $active): bool
|
||||
{
|
||||
return $this->update($userId, [
|
||||
@@ -150,4 +112,3 @@ class User extends Model
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user