public function authenticateAction()
 {
     $form = Editor_Forms_Login::getInstance();
     $request = $this->getRequest();
     if (!$this->getRequest()->isPost()) {
         $this->_helper->redirector('index');
     }
     if (!$form->isValid($this->getRequest()->getPost())) {
         return $this->_forward('index');
     }
     $tenant = $form->getValue('tenant');
     $username = $form->getValue('username');
     $password = $form->getValue('password');
     $login = new Editor_Models_Login();
     $login->setData($tenant, $username, $password);
     if ($login->isValid()) {
         $session = new Zend_Session_Namespace('Zend_Auth');
         // Set the time of user logged in
         $session->setExpirationSeconds(30 * 24 * 3600);
         // If "remember" was marked
         if ((int) $form->getValue('rememberme')) {
             Zend_Session::rememberMe();
         }
         // Clears user specific options which are kept in the session if a new login is made.
         $userOptions = new Zend_Session_Namespace('userOptions');
         $userOptions->unsetAll();
         $this->getHelper('FlashMessenger')->addMessage(_('Succesfully logged in'));
         $this->_helper->redirector('index', 'index');
     } else {
         $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(array_pop($login->getMessages()));
         $this->_helper->redirector('index');
     }
 }
Exemplo n.º 2
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (!in_array($request->getModuleName(), $this->modules)) {
         return;
     }
     $authInstance = Zend_Auth::getInstance();
     //SAML login:
     if (isset($_SERVER['eppn'])) {
         //lookup user with this eduPersonPrincipalName:
         $model = new OpenSKOS_Db_Table_Users();
         $user = $model->fetchRow($model->select()->where('eppn=?', $_SERVER['eppn']));
         if (null !== $user) {
             if ($user->active != 'Y') {
                 Zend_Auth::getInstance()->clearIdentity();
                 Zend_Session::forgetMe();
                 Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Your account is blocked.'));
                 Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'index', 'website');
             }
             $login = new Editor_Models_Login();
             $login->getStorage()->write($user);
             return;
         }
     }
     $resource = $request->getControllerName();
     $actionName = $request->getActionName();
     if ($authInstance->hasIdentity()) {
         if ($authInstance->getIdentity()->active != 'Y') {
             Zend_Auth::getInstance()->clearIdentity();
             Zend_Session::forgetMe();
             Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Your account is blocked.'));
             Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'index', 'website');
         }
     } else {
         if ($request->getControllerName() != 'login') {
             Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'login', 'editor');
         }
     }
 }