示例#1
0
 /**
  * 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
 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;
 }