/** * 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(); }
/** * Profile method * * @param string $redirect * @return void */ public function profile($redirect = null) { $this->prepareView('profile.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'), 'phire' => new Model\Phire())); $this->view->set('title', $this->view->i18n->__('Profile')); if (isset($this->sess->reset_pwd)) { $this->view->set('reset', $this->view->i18n->__('You must reset your password before continuing.')); } $user = new Model\User(); $user->getById($this->sess->user->id); // If user is found and valid if (null !== $user->id) { $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $this->type->id, true, $user->id); // If the form is submitted if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')), $this->project->module('Phire')); // If the form is valid if ($form->isValid()) { $user->update($form, $this->project->module('Phire')); $url = null !== $redirect ? $redirect : $this->request->getBasePath(); if ($url == '') { $url = '/'; } Response::redirect($url); // Else, re-render the form with errors } else { $this->view->set('form', $form); $this->send(); } // Else, render the form } else { $form->setFieldValues($user->getData(null, false)); $this->view->set('form', $form); $this->send(); } } }
/** * Password action method * * @return void */ public function password() { $roleId = $this->getRoleId(); $user = new Model\User(); $users = $user->getAll($roleId); $userIds = []; $this->console->append(); $this->console->append("ID \tUsername\tEmail"); $this->console->append("----\t--------\t-----"); foreach ($users as $user) { $userIds[] = $user->id; $this->console->append($user->id . "\t" . $user->username . "\t\t" . $user->email); } $this->console->append(); $this->console->send(); $userId = null; while (!is_numeric($userId) || !in_array($userId, $userIds)) { $userId = $this->console->prompt($this->console->getIndent() . 'Select User ID: '); } $password = ''; while ($password == '') { $password = $this->console->prompt($this->console->getIndent() . 'Enter New Password: '******'id' => $userId, 'role_id' => $roleId, 'password1' => $password]); $this->console->write(); $this->console->write($this->console->colorize('User Password Updated!', Console::BOLD_GREEN)); }
/** * User edit method * * @return void */ public function edit() { if (null === $this->request->getPath(1)) { Response::redirect($this->request->getBasePath()); } else { $this->prepareView('edit.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'))); $user = new Model\User(); $user->getById($this->request->getPath(1)); // If user is found and valid if (null !== $user->id && $this->view->acl->isAuth('Phire\\Controller\\Phire\\Users\\IndexController', 'edit') && $this->view->acl->isAuth('Phire\\Controller\\Phire\\Users\\IndexController', 'edit_' . $user->type_id)) { $this->view->set('title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . $user->type_name . ' ' . $this->view->separator . ' ' . $user->username)->set('data_title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . $user->type_name . ' ' . $this->view->separator . ' ')->set('typeId', $user->type_id); $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $user->type_id, false, $user->id); // If form is submitted if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8'))); // If form is valid, save the user if ($form->isValid()) { $user->update($form, $this->project->module('Phire')); $this->view->set('id', $user->id); if (null !== $this->request->getPost('update_value') && $this->request->getPost('update_value') == '1') { Response::redirect($this->request->getBasePath() . '/edit/' . $user->id . '?saved=' . time()); } else { if (null !== $this->request->getQuery('update')) { $this->sendJson(array('updated' => '', 'form' => 'user-form')); } else { Response::redirect($this->request->getBasePath() . '/index/' . $form->type_id . '?saved=' . time()); } } // Else, re-render form with errors } else { if (null !== $this->request->getQuery('update')) { $this->sendJson($form->getErrors()); } else { $this->view->set('form', $form); $this->send(); } } // Else, render the form } else { $userData = $user->getData(null, false); $userData['site_ids'] = null !== $userData['site_ids'] ? unserialize($userData['site_ids']) : array(); $form->setFieldValues($userData); $this->view->set('form', $form); $this->send(); } // Else redirect } else { Response::redirect($this->request->getBasePath()); } } }
/** * 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'); } }