示例#1
0
 public function indexAction()
 {
     $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuLogin'), array('action' => 'index'));
     $errors = array();
     $redirectUrl = '';
     if ($this->getRequest()->isPost()) {
         if (\Ilch\Registry::get('user')) {
             $errors['alreadyLoggedIn'] = 'alreadyLoggedIn';
         }
         $emailName = $this->getRequest()->getPost('login_emailname');
         $password = $this->getRequest()->getPost('login_password');
         $redirectUrl = $this->getRequest()->getPost('login_redirect_url');
         if (empty($emailName)) {
             $errors['login_emailname'] = 'fieldEmpty';
         } elseif (empty($password)) {
             $errors['login_password'] = '******';
         } else {
             $result = LoginService::factory()->perform($emailName, $password);
             if ($result->isSuccessful()) {
                 $this->addMessage($this->getTranslator()->trans('loginSuccessful'), 'success');
             } else {
                 $this->addMessage($this->getTranslator()->trans($result->getError()), 'warning');
                 $redirectUrl = array('module' => 'user', 'controller' => 'login', 'action' => 'index');
             }
             $this->redirect($redirectUrl);
         }
         $this->getView()->set('errors', $errors);
     }
     if (!empty($_SESSION['redirect'])) {
         $redirectUrl = $_SESSION['redirect'];
         unset($_SESSION['redirect']);
     }
     $this->getView()->setArray(['errors' => $errors, 'regist_accept' => $this->getConfig()->get('regist_accept'), 'redirectUrl' => $redirectUrl]);
 }
示例#2
0
 /**
  * Shows the standard login page.
  * Takes the request data for the login and tries to login the user.
  */
 public function indexAction()
 {
     $errors = array();
     if ($this->getRequest()->isPost()) {
         if (\Ilch\Registry::get('user')) {
             $errors[] = 'alreadyLoggedIn';
         }
         $emailName = $this->getRequest()->getPost('emailname');
         if ($emailName === '') {
             $errors[] = 'noUserEmailGiven';
         } else {
             $password = $this->getRequest()->getPost('password');
             $language = $this->getRequest()->getPost('language');
             if (!empty($language)) {
                 $_SESSION['language'] = $language;
                 $this->getTranslator()->setLocale($language, true);
             }
             $result = LoginService::factory()->perform($emailName, $password);
             if ($result->isSuccessful()) {
                 $this->redirect(array('controller' => 'index', 'action' => 'index'));
             } else {
                 $errors[] = $result->getError();
             }
         }
         $this->getLayout()->set('emailname', $emailName);
     }
     $this->getLayout()->set('errors', $errors);
     $this->getLayout()->set('languages', $this->getTranslator()->getLocaleList());
 }