mirror of
https://github.com/danielbrendel/hortusfox-web.git
synced 2026-05-08 06:39:48 -05:00
Authentication
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class extends the base model class and represents your associated table
|
||||
*/
|
||||
class UserModel extends \Asatru\Database\Model {
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getAuthUser()
|
||||
{
|
||||
try {
|
||||
$auth_token = ($_COOKIE['auth_token']) ?? null;
|
||||
|
||||
$data = static::raw('SELECT * FROM `' . self::tableName() . '` WHERE token = ?', [$auth_token])->first();
|
||||
if (!$data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getUserById($userId)
|
||||
{
|
||||
try {
|
||||
$data = static::raw('SELECT * FROM `' . self::tableName() . '` WHERE id = ?', [$userId])->first();
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the associated table name of the migration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'users';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user