/** * 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($this->console->getIndent() . 'Enter Email: '); } $email = $username; } else { while ($username == '') { $username = $this->console->prompt($this->console->getIndent() . 'Enter Username: '******''; while (!(new Email())->evaluate($email)) { $email = $this->console->prompt($this->console->getIndent() . 'Enter Email: '); } } } $dupeUser = Table\Users::findBy(['username' => $username]); } $password = ''; while ($password == '') { $password = $this->console->prompt($this->console->getIndent() . 'Enter Password: '******''; while (strtolower($active) != 'y' && strtolower($active) != 'n') { $active = $this->console->prompt($this->console->getIndent() . 'Active? (Y/N): '); } $verified = ''; while (strtolower($verified) != 'y' && strtolower($verified) != 'n') { $verified = $this->console->prompt($this->console->getIndent() . '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->console->write(); $this->console->write($this->console->colorize('User Added!', Console::BOLD_GREEN)); }
/** * 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.')); } else { $role = new Model\Role(); if (!$role->canSendReminder($user->role_id)) { $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, 'That request cannot be processed.')); } } } return $this; }
/** * Profile action method * * @return void */ public function profile() { $this->prepareView('phire/profile.phtml'); $this->view->title = 'Profile'; $user = new Model\User(); $user->getById($this->sess->user->id); $role = new Model\Role(); $role->getById($this->sess->user->role_id); if ($role->email_as_username) { $fields = $this->application->config()['forms']['Phire\\Form\\ProfileEmail']; $fields[2]['role_id']['value'] = $this->sess->user->role_id; $this->view->form = new Form\ProfileEmail($fields); } else { $fields = $this->application->config()['forms']['Phire\\Form\\Profile']; $fields[2]['role_id']['value'] = $this->sess->user->role_id; if ($role->email_required) { $fields[1]['email']['required'] = true; } $this->view->form = new Form\Profile($fields); } $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray()); if ($this->request->isPost()) { $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $fields = $this->view->form->getFields(); $role = new Model\Role(); $role->getById($this->sess->user->role_id); $fields['verified'] = (int) (!$role->verification); $user = new Model\User(); $user->update($fields, $this->sess); $this->view->id = $user->id; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/profile'); } } $this->send(); }
/** * Remove action method * * @return void */ public function remove() { if ($this->request->isPost()) { $role = new Model\Role(); $role->remove($this->request->getPost()); } $this->sess->setRequestValue('removed', true); $this->redirect(BASE_PATH . APP_URI . '/roles'); }
/** * Remove action method * * @return void */ public function remove() { $roleId = $this->getRoleId(); $role = new Model\Role(); $role->remove(['rm_roles' => [$roleId]]); $this->console->write(); $this->console->write($this->console->colorize('Role Removed!', Console::BOLD_RED)); }
/** * Edit action method * * @param int $id * @return void */ public function edit($id) { $user = new Model\User(); $user->getById($id); if (!isset($user->id)) { $this->redirect(BASE_PATH . APP_URI . '/users'); } if ($this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $user->role_id, 'edit')) { $this->prepareView('phire/users/edit.phtml'); $this->view->title = 'Edit User'; $this->view->username = $user->username; $role = new Model\Role(); $role->getById($user->role_id); if ($role->email_as_username) { $fields = $this->application->config()['forms']['Phire\\Form\\UserEmail']; $fields[1]['email']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);'; } else { $fields = $this->application->config()['forms']['Phire\\Form\\User']; $fields[1]['username']['attributes']['onkeyup'] = 'phire.changeTitle(this.value);'; if ($role->email_required) { $fields[2]['email']['required'] = true; } } $roles = $role->getAll(); $roleValues = []; foreach ($roles as $r) { $roleValues[$r->id] = $r->name; } $fields[1]['password1']['required'] = false; $fields[1]['password2']['required'] = false; $fields[0]['role_id']['type'] = 'select'; $fields[0]['role_id']['label'] = 'Role'; $fields[0]['role_id']['value'] = $roleValues; $fields[0]['role_id']['marked'] = $user->role_id; $fields[0]['role_id']['attributes'] = ['onchange' => 'phire.checkUserRole(this);']; $this->view->form = $role->email_as_username ? new Form\UserEmail($fields) : new Form\User($fields); $this->view->form->addFilter('strip_tags', null, 'textarea')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray()); if ($this->request->isPost()) { $this->view->form->addFilter('strip_tags', null, 'textarea')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $user = new Model\User(); $user->update($this->view->form->getFields(), $this->sess); $this->view->id = $user->id; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/users/edit/' . $user->id); } } $this->send(); } else { $this->redirect(BASE_PATH . APP_URI . '/users'); } }