public function Index() { if ($this->request->isPost()) { if (Config::$authentication['authentication']) { $server = isset(Config::$server['server']) && !empty(Config::$server['server']) ? Config::$server['server'] : Config::$server['host'] . ':' . Config::$server['port']; $db = $this->request->getParam('db'); $options = array('username' => $this->request->getParam('username'), 'password' => $this->request->getParam('password'), 'db' => !empty($db) ? $db : 'admin'); $mongo = PHPMongoDB::getInstance($server, $options); if ($mongo->getConnection()) { $seesion = Application::getInstance('Session'); $seesion->isLogedIn = TRUE; $seesion->server = $server; $seesion->options = $options; $this->request->redirect(Theme::URL('Index/Index')); } else { $this->message->error = $mongo->getExceptionMessage(); } } else { if ($this->request->getParam('username') == Config::$authentication['user'] && $this->request->getParam('password') == Config::$authentication['password']) { $server = isset(Config::$server['server']) && !empty(Config::$server['server']) ? Config::$server['server'] : Config::$server['host'] . ':' . Config::$server['port']; $seesion = Application::getInstance('Session'); $seesion->isLogedIn = TRUE; $seesion->server = $server; $seesion->options = array(); $this->request->redirect(Theme::URL('Index/Index')); } else { $this->message->error = I18n::t('AUTH_FAIL'); } } } $data = array(); $this->display('index', $data); }
/** * @param string $server [optional] * @param array $options [optional] * @return mixed (Object of MongoClient|Mongo */ public static function getInstance($server = '', array $options = array()) { if (is_null(self::$instance)) { self::$instance = new self($server, $options); } return self::$instance; }
public function __construct() { $session = Application::getInstance('Session'); $mongo = PHPMongoDB::getInstance($session->server, $session->options); $exception = $mongo->getExceptionMessage(); if ($exception) { exit($exception); } $this->mongo = $mongo->getConnection(); }