Authentication

This commit is contained in:
Daniel Brendel
2023-09-30 18:59:27 +02:00
parent c8c3992a7f
commit 7a644f448f
10 changed files with 128 additions and 3 deletions
+49
View File
@@ -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';
}
}