コード例 #1
0
ファイル: UserLogin.php プロジェクト: rexmac/zyndax
 /**
  * Helper method to display user login info
  *
  * @return string
  */
 public function direct()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $user = Zend_Registry::get('acl')->getUser();
         $profileUrl = $this->view->url(array(), 'userProfile');
         $logoutUrl = $this->view->url(array(), 'logout');
         $username = $user->getUsername();
         if (strlen($username) > 12) {
             $username = substr($username, 0, 6) . '…';
         }
         $markup = '<div class="first">Welcome back: <span class="bold">' . $user->getProfile()->getFirstName() . '</span></div>' . '<div>Login Name: <span class="bold">' . $username . '</span></div>' . '<div><a href="' . $profileUrl . '">Profile</a> | <a href="' . $logoutUrl . '" title="Logout">Logout</a></div>';
         return $markup;
     } else {
         /*$form = new \Application_Form_UserLogin();
           $form->setDecorators(array(
             'FormElements',
             'Form'
           ));
           return $form->render();*/
         $form = new \Application_Form_UserLogin();
         $form->render();
         $markup = '<form id="userLogin" enctype="application/x-www-form-urlencoded" method="post" action="' . $this->view->url(array(), 'login') . '">' . $form->getElement('csrf')->render() . '<label for="loginUsername">Username:</label>' . '<input type="text" name="username" id="loginUsername">' . '<label for="loginPassword">Password:</label>' . '<input type="password" name="password" id="loginPassword">' . '<input type="submit" name="login" id="login" value="Login">' . '</form>';
         return $markup;
     }
 }
コード例 #2
0
ファイル: UserController.php プロジェクト: sgraebner/tp
 public function loginAction()
 {
     $auth = $this->_getAuth();
     if ($auth->hasIdentity()) {
         $this->_redirect($this->url('index'), array('exit' => true));
     }
     $userLoginForm = new Application_Form_UserLogin();
     /** @var $request Zend_Controller_Request_Http */
     $request = $this->getRequest();
     if ($request->isPost() && $userLoginForm->isValid($request->getPost())) {
         $authAdapter = $this->_getAuthAdapter();
         $authAdapter->setIdentity($request->get('username'));
         $authAdapter->setCredential($request->get('password'));
         $authResult = $auth->authenticate($authAdapter);
         if (!$authResult->isValid()) {
             $messages = $authResult->getMessages();
             foreach ($messages as $message) {
                 $this->getFlashMessenger()->addErrorMessage($message, true);
             }
         } else {
             $this->getFlashMessenger()->addSuccessMessage('login successful');
             $this->_redirect($this->url('index'), array('exit' => true));
         }
     }
     $this->view->assign('form', $userLoginForm);
 }
コード例 #3
0
 public function indexAction()
 {
     $this->_helper->layout->setLayout('entrance');
     if (!is_null($this->_session->getSessionId())) {
         $this->redirect('home/fead');
     }
     $request = $this->getRequest();
     $form = new Application_Form_UserLogin();
     $form->setAction('user/login');
     $this->view->form = $form;
 }
コード例 #4
0
 public function loginAction()
 {
     $responseTime = rand(0, 1000000);
     if (!is_null($this->_session->getSessionId())) {
         if (!is_null($this->getParam('redirect'))) {
             $this->view->redirect = $this->getParam('redirect');
         } else {
             $this->redirect('home/fead');
         }
     }
     $this->_helper->layout->setLayout('entrance');
     $request = $this->getRequest();
     $form = new Application_Form_UserLogin();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $email = strtolower($form->getValue('email'));
             $user = $this->_userRepo->login($email, Application_Model_Hash::hash($form->getValue('password')));
             // pending account
             if (is_null($user) && Application_Model_SignUpRepository::getInstance()->emailExists($email)) {
                 $form->getElement('email')->addError($this->_translate->_('login_pending'));
             } else {
                 if (is_null($user) || is_null($user->getEmail())) {
                     $form->getElement('email')->addError($this->_translate->_('login_incorrect'));
                 } else {
                     if ($user->getRole() === 'deactivated') {
                         $form->getElement('email')->addError($this->_translate->_('login_deactivated'));
                     } else {
                         if ($user->getRole() === 'guest') {
                             $form->getElement('email')->addError($this->_translate->_('login_not_validated'));
                         } else {
                             $this->_session->setSessionId($user->getId());
                             usleep($responseTime);
                             // redirect
                             if (!is_null($form->getValue('redirect'))) {
                                 $this->redirect($form->getValue('redirect'));
                             }
                             $this->redirect('home/fead');
                         }
                     }
                 }
             }
         }
     } else {
         if ($this->getParam('redirect')) {
             $form->getElement('redirect')->setValue($this->getParam('redirect'));
         }
     }
     $this->view->form = $form;
 }
コード例 #5
0
ファイル: UserController.php プロジェクト: rexmac/zyndax
 /**
  * Process login using form values
  *
  * @param Application_Form_UserLogin $form
  * @return void
  */
 private function _processAuth(\Application_Form_UserLogin $form)
 {
     $values = $form->getValues();
     $adapter = new DoctrineAuthAdapter();
     $adapter->setIdentity($values['username'])->setCredential($values['password']);
     $auth = Zend_Auth::getInstance();
     $result = $auth->authenticate($adapter);
     switch ($result->getCode()) {
         case AuthResult::FAILURE_IDENTITY_NOT_FOUND:
         case AuthResult::FAILURE_ACCOUNT_LOCKED:
             $message = "Failure - Identity not found";
             break;
         case AuthResult::FAILURE_CREDENTIAL_INVALID:
             $message = "Failure - Credential invalid";
             break;
         case AuthResult::FAILURE_REQUIRES_EMAIL_VERIFICATION:
             $message = "Failure - Account requires email verification";
             break;
         case AuthResult::SUCCESS:
             $message = "Success";
             break;
             // @codeCoverageIgnoreStart
         // @codeCoverageIgnoreStart
         default:
             $message = "Failure - Unknown error";
             // @codeCoverageIgnoreEnd
     }
     $form->addErrorMessage($message);
     if ($result->isValid()) {
         $user = $adapter->getUser();
         session_id();
         $siteDomain = Zend_Registry::get('siteDomain');
         // Track login event
         UserLoginEventService::create(array('user' => $user, 'date' => new DateTime(), 'ip' => $this->getRequest()->getServer('REMOTE_ADDR')));
         $auth->getStorage()->write($user->getId());
         // Set auth cookie
         if (!Zend_Session::$_unitTestEnabled) {
             // @codeCoverageIgnoreStart
             $authCookieName = Zend_Registry::get('config')->session->auth->name;
             $cookieParams = session_get_cookie_params();
             setcookie($authCookieName, 1, 0, $cookieParams['path'], $cookieParams['domain'], $cookieParams['secure'], true);
         }
         // @codeCoverageIgnoreEnd
         return true;
     }
     return false;
 }