コード例 #1
0
ファイル: Plugin.php プロジェクト: tremor-od/pizza.loc
 public function authenticate(MOXMAN_Auth_User $user)
 {
     $config = MOXMAN::getConfig();
     $session = MOXMAN_Http_Context::getCurrent()->getSession();
     // Check logged in key
     $sessionValue = $session->get($config->get("SessionAuthenticator.logged_in_key"), false);
     if (!$sessionValue || $sessionValue === "false") {
         return false;
     }
     // Extend config with session prefixed sessions
     $sessionConfig = array();
     $configPrefix = $config->get("SessionAuthenticator.config_prefix");
     if ($configPrefix) {
         foreach ($_SESSION as $key => $value) {
             if (strpos($key, $configPrefix) === 0) {
                 $sessionConfig[substr($key, strlen($configPrefix) + 1)] = $value;
             }
         }
     }
     // Extend the config with the session config
     $config->extend($sessionConfig);
     // Replace ${user} with all config items
     $key = $config->get("SessionAuthenticator.user_key");
     if ($key && isset($_SESSION[$key])) {
         $config->replaceVariable("user", $session->get($key));
     }
     // The user is authenticated so let them though
     return true;
 }
コード例 #2
0
 /**
  * Wrap Moxiemanager's api.php in a controller action.
  *
  * @return void
  */
 public function api()
 {
     try {
         $pluginPath = Plugin::path('CkTools');
         define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes');
         define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins');
         define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager');
         define('MOXMAN_API_FILE', __FILE__);
         $appConfig = Configure::read('CkTools.moxiemanager');
         Configure::load('CkTools.moxiemanager');
         $moxieManagerConfig = Configure::read('moxiemanager');
         if (is_array($appConfig)) {
             $moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig);
         }
         $GLOBALS['moxieManagerConfig'] = $moxieManagerConfig;
         require_once MOXMAN_CLASSES . '/MOXMAN.php';
         $context = \MOXMAN_Http_Context::getCurrent();
         $pluginManager = \MOXMAN::getPluginManager();
         foreach ($pluginManager->getAll() as $plugin) {
             if ($plugin instanceof \MOXMAN_Http_IHandler) {
                 $plugin->processRequest($context);
             }
         }
     } catch (Exception $e) {
         \MOXMAN_Exception::printException($e);
     }
     return $this->render(false, false);
 }
コード例 #3
0
ファイル: Exception.php プロジェクト: bao2313120/qinzi
 public static function printException(Exception $e)
 {
     // Handle exceptions in authenticators
     $httpContext = MOXMAN_Http_Context::getCurrent();
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     $message = $e->getMessage();
     if (MOXMAN::getConfig()->get("general.debug")) {
         $message .= "\n\nStacktrace:\n";
         $trace = $e->getTrace();
         array_shift($trace);
         $message .= $e->getFile() . ":" . $e->getLine() . "\n";
         foreach ($trace as $item) {
             if (isset($item["file"]) && isset($item["line"])) {
                 $message .= $item["file"] . ":" . $item["line"] . "\n";
             }
         }
     }
     if ($request->get("json")) {
         $response->sendJson((object) array("jsonrpc" => "2.0", "error" => array("code" => $e->getCode(), "message" => $message), "id" => "r0"));
     } else {
         echo nl2br($message);
     }
 }
コード例 #4
0
ファイル: MOXMAN.php プロジェクト: GHarutyunyan/cms
// Load plugins, needs to be loaded at page level since they might contain globals
$plugins = explode(',', MOXMAN::getConfig()->get("general.plugins"));
foreach ($plugins as $plugin) {
    if ($plugin) {
        $pluginPath = MOXMAN_ROOT . '/plugins/' . $plugin;
        MOXMAN_AutoLoader::addPrefixPath("MOXMAN_" . $plugin, $pluginPath);
        $plugin = $pluginPath . "/Plugin.php";
        if (file_exists($plugin)) {
            require_once $plugin;
        }
    }
}
// Load core plugin last
require_once MOXMAN_CLASSES . '/Core/Plugin.php';
// Trigger authenticate on all plugins so it can override any config options
try {
    MOXMAN::getAuthManager()->isAuthenticated();
} catch (Exception $e) {
    // Handle exceptions in authenticators
    $httpContext = MOXMAN_Http_Context::getCurrent();
    $request = $httpContext->getRequest();
    $response = $httpContext->getResponse();
    if ($request->get("json")) {
        $response->sendJson((object) array("jsonrpc" => "2.0", "error" => array("code" => '200', "message" => $e->getMessage()), "id" => "r0"));
    } else {
        die($e->getMessage());
    }
    die;
}
// Initialize all plugins
MOXMAN::getPluginManager()->initAll();