/** * 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; }
/** * 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: '******''; 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: '******''; 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)); }
/** * 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; }
/** * Send a user a forgot password reminder * * @param array $fields * @param string $title * @return void */ public function forgot(array $fields, $title) { $user = Table\Users::findBy(['email' => $fields['email']]); if (isset($user->id)) { $this->data['id'] = $user->id; $notify = new Notification(); $notify->sendReset($user, $title); } }