public static function getLoggedInController() { if ($controller = ControllerManager::getControllerFromSession(__CLASS__)) { return $controller; } else { if (Cookie::exists(Config::get('cookie', 'name'))) { /** @var CookieController $cookieController */ if ($uuid = CookieController::verifyCookie()) { return ControllerManager::getController(__CLASS__, ['uuid' => $uuid], true); } } } return false; }
public static function verifyCookie() { if (Cookie::exists(Config::get('cookie', 'name'))) { $token = Cookie::get(Config::get('cookie', 'name')); $toVerify = hash("sha512", $token . Utils::getClientIP()); if ($data = Database::getInstance()->get(call_user_func(self::getModelClass() . '::getTableName'), ['token' => $toVerify], ['user_uuid'])) { if (array_key_exists(0, $data) && is_array($data[0])) { $data = $data[0]; } if (array_key_exists('user_uuid', $data)) { return $data['user_uuid']; } } Cookie::remove(Config::get('cookie', 'name')); } return false; }