Exemple #1
0
 /**
  * Checks if the user is banned/inactive/suspended/temporary blocked
  *
  * @param NetAssist\Models\Users $user
  */
 public function checkUserFlags(Users $user)
 {
     if ($user->inactive) {
         throw new Exception('The user is inactive');
     }
     if ($user->blocked) {
         throw new Exception('The user is blocked');
     }
     if ($user->lastLoginDate != null) {
         $login_int = $user->failedLoginLastDate->sec - time();
         if ($user->failedLoginBlock && $login_int < $this->config->application->failLoginBlockTime) {
             throw new Exception('The user is temporary blocked');
         } else {
             $user->failedLoginBlock = false;
         }
         $user->save();
     }
 }
Exemple #2
0
 /**
  * Creates the remember me environment settings the related cookies and generating tokens
  *
  * @param NetAssist\Models\Users $user
  */
 public function saveSuccessLogin($user)
 {
     $user->lastLoginDate = new MongoDate(time());
     $user->failedLoginAttempts = 0;
     $user->save();
 }
 /**
  *  Handles user signup (registration) form show and saving
  */
 public function signupAction()
 {
     //Create a new for instance
     $form = new UserSignupForm();
     //Set form
     $this->view->form = $form;
     //FORM GET
     //If we are not posting a form, just return page with blank form
     if (!$this->request->isPost()) {
         //no form to validate
         return;
     }
     //FORM SAVE
     //Check if form is valid, otherwise return form with errors
     if ($form->isValid($this->request->getPost()) != false) {
         //Create a new user
         $user = new Users();
         $user->setEmptyLoginState();
         //Set fields
         $user->login = $this->request->getPost('username', 'striptags');
         $user->email = $this->request->getPost('email');
         $user->password = $this->security->hash($this->request->getPost('password'));
         //Set view form
         $this->view->form = $form;
         //Check for username and email existance to avoid conflicts
         $saveConflict = false;
         if ($this->isUsernameExists($user->name)) {
             //Append flash error
             $this->flash->error("User name already exists!");
             //Append error to the username form field
             $this->appendFormFieldError('username', 'Such user name already exists');
             //Set conflicting state
             $saveConflict = true;
         }
         if ($this->isEmailExists($user->email)) {
             //Append flash error
             $this->flash->error("Email already exists!");
             //Append error to the email address form field
             $this->appendFormFieldError('email', 'Such email already registred!');
             //Set conflicting state
             $saveConflict = true;
         }
         //Set error if we have a conflicting user name or email address
         if ($saveConflict) {
             $this->flash->error("Conflict detected");
             return;
         }
         //Try to save a user into database
         if ($user->save()) {
             return $this->response->redirect();
         }
         //Set page errors flash if we have database errors during save operation
         $this->flash->error($user->getMessages());
     }
 }