/** * 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(); }
/** * User edit type method * * @return void */ public function type() { if (null === $this->request->getPath(1)) { Response::redirect($this->request->getBasePath()); } else { $this->prepareView('type.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->set('title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Type') . ' ' . $this->view->separator . ' ' . $user->username)->set('typeId', $user->type_id); $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', 0, false, 0, $this->project->getService('acl')); // If the form is submitted if ($this->request->isPost()) { $form->setFieldValues(array('type_id' => $this->request->getPost('type_id'))); // If the form is valid, save user type if ($form->isValid()) { $user->updateType($form, $this->project->module('Phire')); Response::redirect($this->request->getBasePath() . '?saved=' . time()); // Else, re-render the form with errors } else { $this->view->set('form', $form); $this->send(); } // Else, render the form } else { $form->setFieldValues(array('type_id' => $user->type_id)); $this->view->set('form', $form); $this->send(); } // Else redirect } else { Response::redirect($this->request->getBasePath()); } } }
/** * Verify method * * @param string $redirect * @return void */ public function verify($redirect = null) { // If the required user ID and hash is submitted if (null !== $this->request->getPath(1) && null !== $this->request->getPath(2)) { $this->prepareView('verify.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'), 'phire' => new Model\Phire(), 'title' => 'Verify')); $this->view->set('title', $this->view->i18n->__('Verify')); $user = new Model\User(); $user->getById($this->request->getPath(1)); // If the user was found, verify and save if (isset($user->id) && sha1($user->email) == $this->request->getPath(2)) { $user->verify(); $message = 'Thank you. Your email has been verified.'; // Else, render failure message } else { $message = 'Sorry. That email could not be verified.'; } if (null !== $redirect) { Response::redirect($redirect); } else { $this->view->set('message', $this->view->i18n->__($message)); $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'); } }