Ejemplo n.º 1
0
 /**
  * Hook into action controller preDispatch() workflow
  *
  * @return void
  */
 public function preDispatch()
 {
     $role = Zend_Registry::get('config')->acl->defaultRole;
     if ($this->_auth->hasIdentity()) {
         $user = $this->_auth->getIdentity();
         if (is_object($user) && !empty($user->role)) {
             $role = $user->role;
         }
     }
     $request = $this->_action->getRequest();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $module = $request->getModuleName();
     $this->_controllerName = $controller;
     $resource = $controller;
     $privilege = $action;
     if (!$this->_acl->has($resource)) {
         $resource = null;
     }
     if ($resource == 'error' && $privilege == 'error') {
         return;
     }
     if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
         $request->setModuleName('default')->setControllerName('auth')->setActionName('noaccess');
         $request->setDispatched(false);
         return;
     }
 }
Ejemplo n.º 2
0
 /**
  * Check, if user is logged in
  *
  * @param  no parameters
  * @return bool logged in status
  */
 public function isLoggedIn()
 {
     if ($this->_zendAuth === null) {
         $this->_zendAuth = Zend_Auth::getInstance();
     }
     return $this->_zendAuth->hasIdentity();
 }
Ejemplo n.º 3
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if ($request->getParam('sid') !== null && $request->getParam('PHPSESSID') === null) {
         $request->setParam('PHPSESSID', $request->getParam('sid'));
     }
     if ($request->getParam('PHPSESSID') === null) {
         $module = strtolower($request->getModuleName());
         $controller = strtolower($request->getControllerName());
         $action = strtolower($request->getActionName());
         $route = $module . '/' . $controller . '/' . $action;
         if (!in_array($route, $this->_whitelist)) {
             if (is_null($this->_auth)) {
                 $auth = Zend_Auth::getInstance();
                 $auth->setStorage(new Zend_Auth_Storage_Session($this->getStorage()));
                 $this->_auth = $auth;
             }
             if (!$this->_auth->hasIdentity()) {
                 $errorHandler = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
                 $errorHandler->type = 'EXCEPTION_NOT_ALLOWED';
                 $errorHandler->exception = new Zend_Controller_Action_Exception('No credentials available');
                 $errorHandler->request = clone $request;
                 $request->setParam('error_handler', $errorHandler)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction());
             } else {
                 $this->_auth->getIdentity()->connect();
                 $this->_auth->getIdentity()->refresh();
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function logoutAction()
 {
     $this->getHelper('contextSwitch')->addActionContext('logout', 'json')->initContext();
     if ($this->auth->hasIdentity()) {
         $this->auth->clearIdentity();
     }
     $this->view->response = 'OK';
 }
Ejemplo n.º 5
0
 /** Get the person's identity
  * @access public
  * @return boolean
  */
 public function getPerson()
 {
     if ($this->_auth->hasIdentity()) {
         return $this->_auth->getIdentity();
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
 public function testSuccess()
 {
     $this->adapter->setIdentity('test')->setCredential('test');
     $result = $this->auth->authenticate($this->adapter);
     $this->assertTrue($result->isValid());
     $this->assertEquals(Zend_Auth_Result::SUCCESS, $result->getCode());
     $this->assertTrue(is_object($this->adapter->getResultUserData()));
 }
Ejemplo n.º 7
0
 protected function _isAuthorized($resource, $action)
 {
     $user = $this->_auth->hasIdentity() ? $this->_auth->getIdentity() : 'guest';
     if (!$this->_acl->has($resource) || !$this->_acl->isAllowed($user, $resource, $action)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 8
0
 /**
  * Ensure expected behavior upon authentication failure
  *
  * @return void
  */
 public function testFailure()
 {
     $auth = new Zend_Auth(new Zend_AuthTest_Failure_Adapter(), false);
     $options = array();
     $token = $auth->authenticate($options);
     $this->assertFalse($token->isValid());
     $this->assertTrue('someIdentity' === $token->getIdentity());
     $this->assertTrue('Failure Message' === $token->getMessage());
 }
Ejemplo n.º 9
0
 protected function _isAuthorized($controller, $action)
 {
     $this->_acl = Zend_Registry::get('acl');
     $user = $this->_auth->getIdentity();
     if (!$this->_acl->has($controller) || !$this->_acl->isAllowed($user, $controller, $action)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
    /**
     * Gets content panel for the Debugbar
     *
     * @return string
     */
    public function getPanel()
    {
        if ($this->_auth->hasIdentity()) {
            $html  = '<h4>Current Identity</h4>';
            $html .= $this->_cleanData($this->_auth->getIdentity());
            return $html;
        }

        return '';
    }
Ejemplo n.º 11
0
 /** Get the user's role
  * @access public
  * @return string
  */
 public function getRole()
 {
     if ($this->_auth->hasIdentity()) {
         $user = $this->_auth->getIdentity();
         $role = $user->role;
     } else {
         $role = 'public';
     }
     return $role;
 }
Ejemplo n.º 12
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $username = '******';
     $role = 'Unknown Role';
     if ($this->_auth->hasIdentity()) {
         foreach ($this->_auth->getIdentity() as $property => $value) {
             $this->message->addRow(array((string) $property, (string) $value));
         }
     } else {
         //			$this->message->setMessage('Not authorized');
     }
     return '';
 }
Ejemplo n.º 13
0
 /**
  *
  * @access public
  * @param Zend_Controller_Request_Abstract $request
  * @return mixed 
  */
 public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
 {
     $this->_request = $request;
     switch (true) {
         case $this->_checkRoute('auth', 'default'):
         case $this->_checkRoute('recovery', 'default'):
             return true;
             break;
         case !$this->_auth->hasIdentity():
             $this->_routeNoAuth();
             break;
     }
 }
Ejemplo n.º 14
0
 /**
  * Initialize the controller
  * sets basic info such as baseUrl
  * 
  * @return void
  */
 public function init()
 {
     parent::init();
     $this->view->baseUrl = $this->_request->getBaseUrl();
     if ($this->_authCheckRequired == true) {
         $this->_generateAuthAdapter();
         if (!$this->_auth->hasIdentity()) {
             $this->_helper->redirector->gotoRoute(array('controller' => 'login', 'action' => 'index'));
         }
     }
     $this->view->styles = array('reset.css', 'main.css', 'jquery-ui.css');
     $this->view->scripts = array('jquery.js', 'jquery-ui.js');
 }
Ejemplo n.º 15
0
 /**
  *(non-PHPdoc)
  *
  * @see Zend_Controller_Plugin_Abstract::preDispatch()
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     /**
      * Recupera a identidade do usuario logado
      *
      * @var Array
      */
     $role = $this->auth->getIdentity();
     /**
      * Recursos que se deseja acesso
      *
      * @var String
      */
     $resource = $this->getRequest()->getModuleName();
     /**
      * Ação permitida dentro de um resource
      *
      * @var String
      */
     $action = $this->getRequest()->getModuleName() != 'admin' && $this->getRequest()->getModuleName() != 'sac' ? null : $this->getRequest()->getControllerName();
     // Verificação condicional para os controllers e actions de upload
     if (!($request->getActionName() == 'upload' || $request->getControllerName() == 'upload')) {
         // Verifica se ha lixo na autenticacao
         if (!is_array($role)) {
             // Parametros
             $params = array();
             // Destroi qualquer instancia de autenticacao
             $this->auth->clearIdentity();
             // Altera a rota de destino
             $request->setModuleName('admin')->setControllerName('login')->setActionName('index');
             return;
         }
         // Verifica se o recurso existe e se o usuario logado tem acesso
         if (!$this->acl->has($resource) || !$this->acl->isAllowed($role['usuario'], $resource, $action)) {
             // Parametros
             $params = array();
             // Redireciona para o controller de login
             if ($role['usuario'] != 'visitante') {
                 $params['erro'] = 'Você não possui permissão de acesso a este recurso.';
                 $request->setModuleName('admin')->setControllerName('index')->setActionName('index')->setParams($params);
             } else {
                 if ($this->getRequest()->getModuleName() == "sac") {
                     $request->setModuleName('sac')->setControllerName('login')->setActionName('index')->setParams($params);
                 } else {
                     $request->setModuleName('admin')->setControllerName('login')->setActionName('index')->setParams($params);
                 }
             }
             return;
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Check permissions before dispatch process
  *
  * @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
  * @param Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $resource = $request->getControllerName();
     $action = $request->getActionName();
     if ($this->_auth->hasIdentity()) {
         $identity = $this->_auth->getStorage()->read();
         $role = $identity->role;
     } else {
         $role = $this->_defaultRole;
     }
     if ($this->_acl->has($resource) && !$this->_acl->isAllowed($role, $resource, $action)) {
         $request->setControllerName('error')->setActionName('deny');
     }
 }
Ejemplo n.º 17
0
 /**
  * Called before an action is dispatched by Zend_Controller_Dispatcher.
  *
  * This callback allows for proxy or filter behavior.  By altering the
  * request and resetting its dispatched flag (via
  * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}),
  * the current action may be skipped.
  *
  * @param  Zend_Controller_Request_Abstract $request
  * @return void
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     // reset role & resource
     Zend_Registry::set('Role', 'guest');
     Zend_Registry::set('Resource', '');
     // check if ErrorHandler wasn't fired
     if ($request->getParam('error_handler')) {
         return;
     }
     $module = $request->getModuleName();
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     $pathInfo = $request->getPathInfo();
     $allow = false;
     if ($this->_auth->hasIdentity()) {
         $userId = $this->_auth->getIdentity();
         $roleId = $this->_auth->getRoleId();
         $rolesList = $this->_em->find('Roles', $roleId);
         $roleName = $rolesList->getRoleName();
         $role = new Zend_Acl_Role($roleName);
     } else {
         $roleName = 'guest';
         $role = new Zend_Acl_Role($roleName);
     }
     $resource = $action == '' ? trim($controller) . '/index' : trim($controller) . '/' . trim($action);
     $resource = $module == 'default' ? $resource : $module . "/" . $resource;
     // on main page resource might be empty
     if ($resource == '') {
         $resource = 'index/index';
     }
     // if resource not exist in db then check permission for controller
     if (!$this->_acl->has($resource) && $action != '') {
         $resource = trim($controller);
     }
     // check if user is allowed to see the page
     $allow = $this->_acl->isAllowed($role, $resource);
     if ($allow == false && $this->_auth->hasIdentity()) {
         // user logged in but denied permission
         $request->setModuleName('default');
         $request->setControllerName('error');
         $request->setActionName('forbidden');
         /* $this->_response->setHeader('Content-type', 'text/html');
                       $this->_response->setHttpResponseCode(403);
                       $this->_response->setBody('<h1>403 - Forbidden</h1>');
         
                       $this->_response->sendResponse(); */
     }
     Zend_Registry::set('Role', $role);
     Zend_Registry::set('Resource', $resource);
 }
 /**
  * preDispatch
  *
  * Funcion que se ejecuta antes de que lo haga el FrontController
  *
  * @param Zend_Controller_Request_Abstract $request Peticion HTTP realizada
  * @return
  * @uses Zend_Auth
  *
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $controllerName = $request->getControllerName();
     // Si el usuario esta autentificado
     if ($this->_auth->hasIdentity()) {
     } else {
         // Si el Usuario no esta identificado y no se dirige a la página de Login
         if ($controllerName != 'login') {
             // Mostramos al usuario el Formulario de Login
             $request->setControllerName("login");
             $request->setActionName("index");
         }
     }
 }
Ejemplo n.º 19
0
 /**
  * Returns an instance of Zend_Auth
  *
  * Singleton pattern implementation
  *
  * @return Zend_Auth Provides a fluent interface
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Ejemplo n.º 20
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $auth = Zend_Auth::getInstance();
     $isAllowed = false;
     $controller = $request->getControllerName();
     $action = $request->getActionName();
     // Generate the resource name
     $resourceName = $controller . '/' . $action;
     // Don't block errors
     if ($resourceName == 'error/error') {
         return;
     }
     $resources = $this->acl->getResources();
     if (!in_array($resourceName, $resources)) {
         $request->setControllerName('error')->setActionName('error')->setDispatched(true);
         throw new Zend_Controller_Action_Exception('This page does not exist', 404);
         return;
     }
     // Check if user can access this resource or not
     $isAllowed = $this->acl->isAllowed(Zend_Registry::get('role'), $resourceName);
     // Forward user to access denied or login page if this is guest
     if (!$isAllowed) {
         if (!Zend_Auth::getInstance()->hasIdentity()) {
             $forwardAction = 'login';
         } else {
             $forwardAction = 'deny';
         }
         $request->setControllerName('index')->setActionName($forwardAction)->setDispatched(true);
     }
 }
Ejemplo n.º 21
0
 protected function _initView()
 {
     // Start initail view
     $this->bootstrap('layout');
     $config = $this->getOption('views');
     $resources = $this->getOption('resources');
     $view = new Zend_View();
     if (isset($resources['layout']['layoutPath'])) {
         $view->assign('layoutRootPath', $resources['layout']['layoutPath']);
     }
     $this->bootstrap('db');
     Zend_Loader::loadClass('Ht_Utils_SystemSetting');
     $sysSetting = Ht_Utils_SystemSetting::getSettings();
     $view->assign('sysSetting', $sysSetting);
     $view->assign('profile', Zend_Auth::getInstance()->getIdentity());
     Zend_Loader::loadClass("Ht_Model_SystemSetting");
     $this->setSystemLogConfiguration($sysSetting);
     // use the viewrenderer to keep the code DRY
     // instantiate and add the helper in one go
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');
     $viewRenderer->setView($view);
     $viewRenderer->setViewSuffix('phtml');
     // add it to the action helper broker
     Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
     /**
      * Set inflector for Zend_Layout
      */
     $inflector = new Zend_Filter_Inflector(':script.:suffix');
     $inflector->addRules(array(':script' => array('Word_CamelCaseToDash', 'StringToLower'), 'suffix' => 'phtml'));
     // Initialise Zend_Layout's MVC helpers
     $this->getResource('layout')->setLayoutPath(realpath($resources['layout']['layoutPath']))->setView($view)->setContentKey('content')->setInflector($inflector);
     return $this->getResource('layout')->getView();
 }
Ejemplo n.º 22
0
 public function indexAction()
 {
     // display the profile form and populate if profile exists
     $request = $this->getRequest();
     $form = new Application_Form_Profile();
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     $profileMapper = new Application_Model_ProfileMapper();
     $profile = new Application_Model_Profile();
     $exists = $profileMapper->exists($identity->id);
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $profile->setOptions($form->getValues());
             $profile->setUserId($identity->id);
             $profileMapper->save($profile, $exists);
             // display success message
             $this->view->msg = "<p class='msg'>Profile saved</p>";
         }
     } else {
         $profileMapper->find($identity->id, $profile);
         $data = array('first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'birthdate' => date_format(new DateTime($profile->getBirthdate()), 'Y-m-d'), 'gender' => $profile->getGender());
         $form->populate($data);
     }
     $this->view->form = $form;
 }
Ejemplo n.º 23
0
 public function init($styles = array())
 {
     // Init messages
     $this->view->message = array();
     $this->view->infoMessage = array();
     $this->view->errorMessage = array();
     $this->messenger = new Zend_Controller_Action_Helper_FlashMessenger();
     $this->messenger->setNamespace('messages');
     $this->_helper->addHelper($this->messenger);
     $this->errorMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
     $this->errorMessenger->setNamespace('errorMessages');
     $this->_helper->addHelper($this->errorMessenger);
     $this->infoMessenger = new Zend_Controller_Action_Helper_FlashMessenger();
     $this->infoMessenger->setNamespace('infoMessages');
     $this->_helper->addHelper($this->infoMessenger);
     // Setup breadcrumbs
     $this->view->breadcrumbs = $this->buildBreadcrumbs($this->getRequest()->getRequestUri());
     $this->view->user = Zend_Auth::getInstance()->getIdentity();
     // Set the menu active element
     $uri = $this->getRequest()->getPathInfo();
     if (strrpos($uri, '/') === strlen($uri) - 1) {
         $uri = substr($uri, 0, -1);
     }
     if (!is_null($this->view->navigation()->findByUri($uri))) {
         $this->view->navigation()->findByUri($uri)->active = true;
     }
     $this->view->styleSheets = array_merge(array('css/styles.css'), $styles);
     $translate = Zend_Registry::get('tr');
     $this->view->tr = $translate;
     $this->view->setEscape(array('Lupin_Security', 'escape'));
 }
 public function preRender()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $controller = sgContext::getInstance()->getController();
         if ($controller instanceof FlatCMSPluginController) {
             $session = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace());
             $session->FlatCMSEditorPluginFileMTime = filemtime(FlatCMSPluginPageModel::getPagePath(sgContext::getInstance()->getCurrentPath()));
             //figure out better way to handle this so libraries aren't double loaded
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.min.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.mini.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.autogrow.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/tinymce/jscripts/tiny_mce/jquery.tinymce.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/jquery.jeditable.tinymce.js');
             $controller->scripts[] = sgToolkit::url('/js/FlatCMSEditorPlugin/init.js');
             $controller->js_settings['FlatCMSEditorPlugin'] = array('saveURL' => sgToolkit::url(sgConfiguration::get('routing.FlatCMSEditorPlugin_save.path')), 'currentPath' => sgContext::getInstance()->getCurrentPath());
             if (isset($controller->content) && is_array($controller->content)) {
                 $textarea_fields = sgConfiguration::get('settings.FlatCMSEditorPlugin.textarea_fields', array());
                 foreach ($controller->content as $key => &$field) {
                     if (in_array($key, $textarea_fields)) {
                         $field = '<div class="editable-area" id="' . $key . '">' . $field . '</div>';
                     } else {
                         $field = '<div class="editable" id="' . $key . '">' . $field . '</div>';
                     }
                 }
             }
         }
     }
 }
 /**
  * Show sidebar
  *
  * @var int $pcategory Selected category
  *     
  * @throws Exception 404, Category not found
  *        
  */
 public function sidebarAction()
 {
     $categoriesModel = new Model_DbTable_Categories();
     $select = $categoriesModel->select();
     $select->order(new Zend_Db_Expr('`order`<=-100'))->order("order");
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         $select->where("`order` != -100 OR `order` IS NULL");
     }
     if (NULL != ($category_id = $this->getRequest()->getParam("category"))) {
         if (!($category = $categoriesModel->find($category_id)->current())) {
             throw new Exception("Category not found", 404);
         }
         $select->where("parent_id = ?", $category->id);
         $categories = $categoriesModel->fetchAll($select);
         if (count($categories) == 0) {
             $category = $categoriesModel->find($category->parent_id)->current();
             $categories = $category->findDependentRowset("Model_DbTable_Categories");
         }
     } else {
         $category = NULL;
         $categories = $categoriesModel->fetchAll($select->where("parent_id = ?", 0));
     }
     $this->view->categories = $categories;
     $this->view->category = $category;
     $this->view->current = $category_id;
     $this->view->catalogs = new Zend_Config_Xml(APPLICATION_PATH . "/config/catalogs.xml");
 }
Ejemplo n.º 26
0
 function preDispatch()
 {
     $auth = Zend_Auth::getInstance();
     if (!$auth->hasIdentity()) {
         $this->_redirect('auth/login');
     }
 }
Ejemplo n.º 27
0
    /**
     * Get all accepted submissions belonging to a conference
     *
     * @param integer $conferenceId conference_id
     * @param string $empty String containing the empty value to display
     */
    public function getSubmissionsForSelect($conferenceId = null, $empty = null)
    {
        $return = array();
        if ($empty) {
            $return[0] = $empty;
        }
        $identity = Zend_Auth::getInstance()->getIdentity();
        $query = 'select st.submission_id, s.title from submission_status st
		left join submissions s ON s.submission_id = st.submission_id
		where st.status = :status AND s.conference_id = :conference_id';
        if (!$identity->isAdmin()) {
            // if user is not admin, only show their own submissions
            $mySubmissions = implode(",", array_keys($identity->getMySubmissions()));
            if (!empty($mySubmissions)) {
                $query .= ' and st.submission_id IN (' . $mySubmissions . ')';
            } else {
                return array();
            }
        }
        $submissions = $this->getAdapter()->query($query, array('status' => $this->_getAcceptedValue(), 'conference_id' => $this->getConferenceId()));
        foreach ($submissions as $submission) {
            $return[$submission['submission_id']] = $submission['title'];
        }
        return $return;
    }
Ejemplo n.º 28
0
 public function loggedInAs()
 {
     $Auth = Zend_Auth::getInstance();
     $Ret = '';
     if ($Auth->hasIdentity()) {
         $Username = $Auth->getIdentity()->Nome . ' ' . $Auth->getIdentity()->Cognome;
         $Module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
         $LogoutURL = $this->view->url(array('controller' => 'login', 'action' => 'logout', 'module' => 'default'), 'default', true);
         $MessaggiURL = $this->view->url(array('controller' => 'messages', 'action' => 'index', 'module' => 'default'), 'default');
         $AdminURL = $this->view->url(array('controller' => 'index', 'action' => 'index', 'module' => $Module == 'admin' ? 'default' : 'admin'), 'default');
         #$Ret .= 'Welcome ' . $Username . ' ';
         $Ret .= '<a href="' . $MessaggiURL . '">' . $this->view->img('images/icons/mail_24x24.png', array('title' => 'Messages', 'alt' => 'Messages')) . '</a> ';
         $Ret .= '<a href="' . $AdminURL . '">' . $this->view->img('images/icons/' . ($Module == 'admin' ? 'magic_wand' : 'wrench') . '_24x24.png', array('title' => $Module == 'admin' ? 'Public' : 'Admin', 'alt' => $Module == 'admin' ? 'Public' : 'Admin')) . '</a> ';
         $Ret .= '<a href="' . $LogoutURL . '">' . $this->view->img('images/icons/lock_24x24.png', array('title' => 'Logout', 'alt' => 'Logout')) . '</a>';
         return $Ret;
     }
     $Request = Zend_Controller_Front::getInstance()->getRequest();
     $Controller = $Request->getControllerName();
     $Action = $Request->getActionName();
     if ($Controller == 'login' && $Action == 'index') {
         return '';
     }
     $LoginURL = $this->view->url(array('controller' => 'login', 'action' => 'index'), 'default');
     $Ret .= '<a href="' . $LoginURL . '">' . $this->view->img('images/icons/unlock_24x24.png', array('title' => 'Login', 'alt' => 'Login')) . '</a>';
     return $Ret;
 }
Ejemplo n.º 29
0
    public function loggedInAs()
    {
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $user = $auth->getIdentity();
            if (!isset($user->username)) {
                $auth->clearIdentity();
                $info = 'logout';
                return $info;
            }
            $logoutUrl = $this->view->url(array('controller' => 'auth', 'action' => 'logout'), null, true);
            $url = $this->view->url(array('controller' => 'user', 'action' => 'edit', 'id' => $user->id));
            $info = '<div class ="menuButton"><span class="menu">' . $user->username . '</span>';
            $info .= '<ul> 
					<li><a href="' . $url . '">Mon profil</a></li>
					<li class="separator">​</li>
					<li><a href="' . $logoutUrl . '" class="logout">se déconnecter</a></li>
					</ul></div>';
            return $info;
        }
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
        if ($controller == 'auth' && $action == 'index') {
            return '';
        }
        $form = new Application_Form_Login();
        $loginUrl = $this->view->url(array('controller' => 'auth', 'action' => 'index'), null, true);
        $info = '<div class ="menuButton"><span class="menu"> Se connecter </span><ul><li class="form">' . $form->setAction($loginUrl) . '</li></ul></div>';
        return $info;
        //$loginUrl = $this->view->url(array('controller'=>'auth', 'action'=>'index'));
        //return '<a href="'.$loginUrl.'">Login</a>';
    }
Ejemplo n.º 30
-1
 public function processAction()
 {
     $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Registry::get('dbAdapter'));
     $authAdapter->setTableName('user')->setIdentityColumn('username')->setCredentialColumn('password')->setIdentity($_POST['username'])->setCredential($_POST['password']);
     $auth = Zend_Auth::getInstance();
     $result = $auth->authenticate($authAdapter);
     $data = array();
     if ($result->isValid()) {
         unset($this->_session->messages);
         $identity = $auth->getIdentity();
         $user = new User();
         $user->username = $identity;
         $user->populateWithUsername();
         Zend_Auth::getInstance()->getStorage()->write($user);
         //$this->_redirect('login/complete');
         //$this->_forward('index','main');
         $data['msg'] = __("Login successful.");
         $data['code'] = 200;
     } else {
         $auth->clearIdentity();
         $this->_session->messages = $result->getMessages();
         //$this->_redirect('login');
         $data['err'] = __("Invalid username/password.");
         $data['code'] = 404;
     }
     header('Content-Type: application/xml;');
     $this->view->data = $data;
     $this->completeAction();
     //$this->render();
 }