芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/status.pulsehost.co.uk/app/core/Authentication.php
0 && $user = (new User())->get_user_by_user_id_and_token_code($_COOKIE['user_id'], $_COOKIE['token_code']) ) { if(isset($_COOKIE['user_password_hash']) && $_COOKIE['user_password_hash'] == md5($user->password)) { self::$is_logged_in = true; self::$user_id = $user->user_id; self::$user = $user; return true; } } /* Check the Session */ if( isset($_SESSION['user_id']) && !empty($_SESSION['user_id']) && $user = (new User())->get_user_by_user_id($_SESSION['user_id']) ) { if(isset($_SESSION['user_password_hash']) && $_SESSION['user_password_hash'] == md5($user->password ?? '')) { self::$is_logged_in = true; self::$user_id = $user->user_id; self::$user = $user; return true; } } return false; } public static function is_admin() { if(!self::check()) { return false; } return self::$user->type > 0; } public static function guard($permission = 'user') { switch ($permission) { case 'guest': if(self::check()) { redirect(isset($_GET['redirect']) ? $_GET['redirect'] : 'dashboard'); } break; case 'user': if(!self::check()) { redirect('login?redirect=' . \Altum\Router::$original_request . '?' . \Altum\Router::$original_request_query); } /* Check if user is banned */ if(self::$user->status != 1) { self::logout(); } break; case 'admin': if(!self::check()) { redirect('login?redirect=' . \Altum\Router::$original_request . '?' . \Altum\Router::$original_request_query); } /* Check if user is banned */ if(self::$user->status != 1) { self::logout(); } /* Check if user is admin */ if(self::$user->type != 1) { redirect('dashboard'); } break; } } public static function logout($page = '') { if(self::check()) { db()->where('user_id', self::$user_id)->update('users', ['token_code' => '']); /* Clear the cache */ cache()->deleteItemsByTag('user_id=' . self::$user_id); } session_destroy(); setcookie('user_id', '', time()-30, COOKIE_PATH); setcookie('token_code', '', time()-30, COOKIE_PATH); setcookie('user_password_hash', '', time()-30, COOKIE_PATH); if($page !== false) { redirect($page); } } public static function get_authorization_bearer() { $headers = getallheaders(); $authorization_header = $headers['Authorization'] ?? $headers['authorization'] ?? null; if(!$authorization_header) { return null; } if(!preg_match('/Bearer\s(\S+)/', $authorization_header, $matches)) { return null; } return $matches[1]; } }