Exemple #1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return User
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username) {
         // Check for dupe username and email
         $user = null;
         $email = null;
         if (null !== $this->username) {
             $user = Table\Users::findBy(['username' => $this->username]);
             if (isset($user->id) && $this->id != $user->id) {
                 $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, 'That username already exists.'));
             }
         }
         if (null !== $this->email) {
             $email = Table\Users::findBy(['email' => $this->email]);
             if (isset($email->id) && $this->id != $email->id) {
                 $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email already exists.'));
             }
         }
         // If existing user
         if ((int) $_POST['id'] > 0) {
             if (!empty($this->password1)) {
                 $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
             }
             // Else, if new user, check email and password matches
         } else {
             $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
         }
     }
     return $this;
 }
Exemple #2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Forgot
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->email) {
         $user = Table\Users::findBy(['email' => $this->email]);
         if (!isset($user->id)) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email does not exist.'));
         }
     }
     return $this;
 }
 /**
  * Add action method
  *
  * @return void
  */
 public function add()
 {
     $roleId = $this->getRoleId();
     $username = '';
     $email = null;
     $role = new Model\Role();
     $role->getById($roleId);
     $this->console->write();
     $dupeUser = Table\Users::findBy(['username' => $username]);
     while ($username == '' || isset($dupeUser->id)) {
         if (isset($dupeUser->id)) {
             $this->console->write($this->console->colorize('That username already exists.', Console::BOLD_RED));
             $username = '';
         }
         if ($role->email_as_username) {
             while (!(new Email())->evaluate($username)) {
                 $username = $this->console->prompt('Enter Email: ');
             }
             $email = $username;
         } else {
             while ($username == '') {
                 $username = $this->console->prompt('Enter Username: ');
             }
             if ($role->email_required) {
                 $email = '';
                 while (!(new Email())->evaluate($email)) {
                     $email = $this->console->prompt('Enter Email: ');
                 }
             }
         }
         $dupeUser = Table\Users::findBy(['username' => $username]);
     }
     $password = '';
     while ($password == '') {
         $password = $this->console->prompt('Enter Password: ');
     }
     $active = '';
     while (strtolower($active) != 'y' && strtolower($active) != 'n') {
         $active = $this->console->prompt('Active? (Y/N): ');
     }
     $verified = '';
     while (strtolower($verified) != 'y' && strtolower($verified) != 'n') {
         $verified = $this->console->prompt('Verified? (Y/N): ');
     }
     $fields = ['role_id' => $roleId, 'username' => $username, 'password1' => $password, 'email' => $email, 'active' => strtolower($active) == 'y' ? 1 : 0, 'verified' => strtolower($verified) == 'y' ? 1 : 0];
     $user = new Model\User();
     $user->save($fields, $this->application->config()['application_title']);
     $this->console->write();
     $this->console->write($this->console->colorize('User Added!', Console::BOLD_GREEN));
 }
Exemple #4
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Profile
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->username) {
         // Check for dupe username
         $user = null;
         if (null !== $this->username) {
             $user = Table\Users::findBy(['username' => $this->username]);
             if (isset($user->id) && $this->id != $user->id) {
                 $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, 'That username is not allowed.'));
             }
         }
         // Check for dupe email
         $email = Table\Users::findBy(['email' => $this->email]);
         if (isset($email->id) && $this->id != $email->id) {
             $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That email is not allowed.'));
         }
         // Check password matches
         if (!empty($this->password1)) {
             $this->getElement('password2')->setRequired(true)->addValidator(new Validator\Equal($this->password1, 'The passwords do not match.'));
         }
     }
     return $this;
 }
Exemple #5
0
 /**
  * Get all users
  *
  * @return array
  */
 public function getAllUsers()
 {
     return Table\Users::findAll()->rows();
 }
Exemple #6
0
 /**
  * Get count of users
  *
  * @param  int    $roleId
  * @param  string $username
  * @param  array  $deniedRoles
  * @return int
  */
 public function getCount($roleId = null, $username = null, array $deniedRoles = [])
 {
     $params = [];
     $sql = Table\Users::sql();
     $sql->select();
     if (null !== $username) {
         $sql->select()->where('username LIKE :username');
         $params['username'] = $username . '%';
     }
     if (null !== $roleId) {
         $sql->select()->where('role_id = :role_id');
         $params['role_id'] = $roleId;
     }
     if (count($deniedRoles) > 0) {
         foreach ($deniedRoles as $key => $denied) {
             $sql->select()->where('role_id != :role_id' . ($key + 1));
             $params['role_id' . ($key + 1)] = $denied;
         }
     }
     if (count($params) > 0) {
         return Table\Users::execute((string) $sql, $params, Table\Users::ROW_AS_ARRAY)->count();
     } else {
         return Table\Users::findAll(null, Table\Users::ROW_AS_ARRAY)->count();
     }
 }