Esempio n. 1
0
 /**
  * Get the entity related to user in the active identity.
  *
  * @return Phalcon\UserPlugin\Models\User\User
  */
 public function getUser()
 {
     $identity = $this->session->get('auth-identity');
     if (!isset($identity['id'])) {
         return false;
     }
     $user = User::findFirstById($identity['id']);
     if ($user == false) {
         throw new Exception('The user does not exist');
     }
     return $user;
 }
 /**
  * Shows the forgot password form
  */
 public function forgotPasswordAction()
 {
     $form = new ForgotPasswordForm();
     if ($this->request->isPost()) {
         if (!$form->isValid($this->request->getPost())) {
             foreach ($form->getMessages() as $message) {
                 $this->flash->error($message);
             }
         } else {
             $email = trim(strtolower($this->request->getPost('email')));
             $user = User::findFirstByEmail($email);
             if (!$user) {
                 $this->flash->error('There is no account associated to this email');
             } else {
                 $resetPassword = new UserResetPasswords();
                 $resetPassword->setUserId($user->getId());
                 if ($resetPassword->save()) {
                     $this->flashSession->success('Success! Please check your messages for an email reset password');
                     $this->view->disable();
                     return $this->response->redirect($this->_activeLanguage . '/user/forgotPassword');
                 } else {
                     foreach ($resetPassword->getMessages() as $message) {
                         $this->flash->error($message);
                     }
                 }
             }
         }
     }
     $this->view->form = $form;
 }
Esempio n. 3
0
 /**
  * Checks if the user is banned/inactive/suspended.
  *
  * @param Phalcon\UserPlugin\Models\User\User $user
  */
 public function checkUserFlags($user)
 {
     if ($user->getStatus() === User::STATUS_INACTIVE) {
         throw new Exception('The user is inactive');
     }
     if ($user->getStatus() === User::STATUS_BANNED) {
         throw new Exception('The user is banned');
     }
     if ($user->getStatus() === User::STATUS_SUSPENDED) {
         throw new Exception('The user is suspended');
     }
 }