예제 #1
0
 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $di = self::getDi();
     try {
         $exists = Model\User::count(array('username = :name:', 'bind' => array('name' => $value)));
         if (!$exists) {
             $txt = $this->getOption('message') ? $this->getOption('message') : 'User not found';
             $validator->appendMessage(new Message($txt, $attribute));
             return false;
         }
         return true;
     } catch (\Exception $e) {
         die($e->getMessage());
         $validator->appendMessage(new Message('General form error', $attribute));
         return false;
     }
     return true;
 }
예제 #2
0
 public function loginAction()
 {
     if ($this->session->get('auth')) {
         return $this->response->redirect('user');
     }
     $form = new UserForm\Login();
     if ($this->request->isPost()) {
         $model = new \stdClass();
         $form->bind($this->request->getPost(), $model);
         if ($form->isValid()) {
             $user = Model\User::findFirst(array('username = :name:', 'bind' => array('name' => $model->username)));
             if (password_verify($model->password, $user->password)) {
                 $this->session->set('auth', $user);
                 return $this->response->redirect('user');
             }
             $this->flashSession->error('Username or password incorrect');
         }
     }
     $this->view->form = $form;
     $this->view->site = 'guest';
     $this->view->title = 'Login';
 }
예제 #3
0
 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $di = self::getDi();
     $web_user = $di->get('session')->get('auth', null);
     try {
         // Only verifiy if guest or same username not submited
         if (!$web_user || $web_user->role == \Library\Base\Auth::ROLE_GUEST || $web_user->username != $value) {
             $exists = Model\User::count(array('username = :name:', 'bind' => array('name' => $value)));
             if ($exists) {
                 $txt = $this->getOption('message') ? $this->getOption('message') : 'Email already registered';
                 $validator->appendMessage(new Message($txt, $attribute));
                 return false;
             }
         }
         return true;
     } catch (\Exception $e) {
         die($e->getMessage());
         $validator->appendMessage(new Message('General form error', $attribute));
         return false;
     }
     return true;
 }