login
This commit is contained in:
@ -33,6 +33,11 @@ class UserService
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getByField(string $field, string $value)
|
||||
{
|
||||
return User::where($field, $value)->first();
|
||||
}
|
||||
|
||||
public static function createUsernameArr(): array
|
||||
{
|
||||
foreach (User::all()->toArray() as $user) {
|
||||
@ -45,4 +50,26 @@ class UserService
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getAuthUser()
|
||||
{
|
||||
if (isset($_COOKIE['user_id'])){
|
||||
$user = User::where("id", $_COOKIE['user_id'])->first();
|
||||
if ($user){
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getAuthUsername(): string
|
||||
{
|
||||
$user = self::getAuthUser();
|
||||
if ($user){
|
||||
return $user->username;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user