예제 #1
0
 /**
  * Executed before validation
  *
  * @param array                            $data
  * @param object                           $entity
  * @param Phalcon\Validation\Message\Group $messages
  */
 public function beforeValidation($data, $entity, $messages)
 {
     if ($this->request->getHttpHost() != 'admin.mydomain.com') {
         $messages->appendMessage(new Message('Users only can log on in the administration domain'));
         return false;
     }
     return true;
 }
예제 #2
0
 /**
  * Sign in Action
  *
  * @package     las
  * @version     1.0
  */
 public function signinAction()
 {
     if ($this->request->hasPost('submit_signin') && $this->request->hasPost('username') && $this->request->hasPost('password')) {
         $login = Auth::instance()->login($this->request->getPost('username'), $this->request->getPost('password'), $this->request->getPost('rememberMe') ? TRUE : FALSE);
         if (!$login) {
             $errors = new \Phalcon\Validation\Message\Group();
             if ($login === NULL) {
                 $errors->appendMessage(new \Phalcon\Validation\Message(__('Field :field is incorrect', array(':field' => __('Username'))), 'username', 'Incorrect'));
             } else {
                 $errors->appendMessage(new \Phalcon\Validation\Message(__('Field :field is incorrect', array(':field' => __('Password'))), 'password', 'Incorrect'));
             }
             $this->view->setVar('errors', $errors);
             $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
         } else {
             $referer = $this->request->getHTTPReferer();
             $needBackRedirect = !empty($referer) && strpos(parse_url($referer, PHP_URL_PATH), '/user/signin') !== 0 && parse_url($referer, PHP_URL_HOST) == $this->request->getHttpHost();
             if ($needBackRedirect) {
                 return $this->response->setHeader("Location", $referer);
             } else {
                 return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             }
         }
     }
 }