login
This commit is contained in:
@ -7,10 +7,13 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string $username
|
||||
* @property string $email
|
||||
* @property string $password_hash
|
||||
* @method static where(int[] $array)
|
||||
* @method static find($id)
|
||||
*/
|
||||
class User extends Model {
|
||||
|
||||
const DEFAULT_USER_ROLE = 1;
|
||||
const ADMIN_USER_ROLE = 9;
|
||||
|
||||
protected $table = 'user';
|
||||
protected $fillable = ['username', 'email', 'password_hash', 'role'];
|
||||
protected array $dates = ['deleted at'];
|
||||
|
@ -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