public function beforeDispatch() { if (!Phalcon_Session::get('auth')) { Flash::error('You don\'t have access to this module', 'alert alert-error'); $this->_forward('index/index'); } }
/** * Builds header menu with left and right items * * @param Phalcon_View $view * @return string */ public static function getMenu($view) { $auth = Phalcon_Session::get('auth'); if ($auth) { self::$_headerMenu['pull-right']['session'] = array('caption' => 'Log Out', 'action' => 'end'); } else { unset(self::$_headerMenu['pull-left']['invoices']); } echo '<div class="nav-collapse">'; $controllerName = $view->getControllerName(); foreach (self::$_headerMenu as $position => $menu) { echo '<ul class="nav ', $position, '">'; foreach ($menu as $controller => $option) { if ($controllerName == $controller) { echo '<li class="active">'; } else { echo '<li>'; } echo Phalcon_Tag::linkTo($controller . '/' . $option['action'], $option['caption']); echo '</li>'; } echo '</ul>'; } echo '</div>'; }
/** * Edit the active user profile * */ public function profileAction() { //Get session info $auth = Session::get('auth'); //Query the active user $user = Users::findFirst($auth['id']); if ($user == false) { $this->_forward('index/index'); } if (!$this->request->isPost()) { Tag::setDefault('name', $user->name); Tag::setDefault('email', $user->email); } else { $name = $this->request->getPost('name', 'string'); $email = $this->request->getPost('email', 'email'); $name = strip_tags($name); $user->name = $name; $user->email = $email; if ($user->save() == false) { foreach ($user->getMessages() as $message) { Flash::error((string) $message, 'alert alert-error'); } } else { Flash::success('Your profile information was updated successfully', 'alert alert-success'); } } }
public static function disclaimer($translate) { if (!Phalcon_Session::get('disclaimer')) { echo '<div class="alert alert-info"> <a class="close" data-dismiss="alert" href="#">×</a> ', $translate->_('disclaimer', array('framework' => '<a href="http://phalconphp.com">Phalcon PHP Framework</a>', 'official' => '<a href="https://www.php.net">' . $translate['accessOf'] . '</a>')), ' </div>'; Phalcon_Session::set('disclaimer', true); } }
protected function _getTransPath() { $translationPath = '../app/messages/'; $language = Phalcon_Session::get("language"); if (!$language) { Phalcon_Session::set("language", "en"); } if ($language === 'es' || $language === 'en') { return $translationPath . $language; } else { return $translationPath . 'en'; } }
public function setLanguageAction($language = '') { //Change the language, reload translations if needed if ($language == 'en' || $language == 'es') { Phalcon_Session::set('language', $language); $this->loadMainTrans(); $this->loadCustomTrans('index'); } //Go to the last place $referer = $this->request->getHTTPReferer(); if (strpos($referer, $this->request->getHttpHost() . "/") !== false) { return $this->response->setHeader("Location", $referer); } else { return $this->_forward("index/index"); } }
<?php error_reporting(E_ALL); try { require __DIR__ . '/../app/config/config.php'; require __DIR__ . '/../app/config/routes.php'; require __DIR__ . '/../vendor/loader.php'; Phalcon_Session::start(); $front = Phalcon_Controller_Front::getInstance(); $front->setRouter($router); $front->setConfig($config); echo $front->dispatchLoop()->getContent(); } catch (Phalcon_Exception $e) { echo "PhalconException: ", $e->getMessage(); }
/** * Register authenticated user into session data * * @param Users $user */ private function _registerSession($user) { Phalcon_Session::set('auth', array('id' => $user->id, 'name' => $user->name)); }