/** * 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(); } } }
/** * Install initial user method * * @return void */ public function user() { // If the system is installed if (DB_INTERFACE != '' && DB_NAME != '' && !isset($this->sess->config)) { Response::redirect(BASE_PATH . APP_URI); // Else, if the initial install screen or config isn't complete } else { if (DB_INTERFACE == '' && DB_NAME == '') { if (isset($this->sess->config)) { Response::redirect(BASE_PATH . (isset($this->sess->app_uri) ? $this->sess->app_uri : APP_URI) . '/install/config?lang=' . $_GET['lang']); } else { Response::redirect(BASE_PATH . (isset($this->sess->app_uri) ? $this->sess->app_uri : APP_URI) . '/install?lang=' . $_GET['lang']); } // Else, install the first system user } else { $user = new Model\User(array('title' => $this->i18n->__('User Setup'))); $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri() . '?lang=' . $this->i18n->getLanguage() . '_' . $this->i18n->getLocale(), 'post', 2001, true); if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if ($form->isValid()) { $user->save($form, $this->project->module('Phire')); $newUser = Table\Users::findById($user->id); if (isset($newUser->id)) { $newUser->site_ids = serialize(array(0)); $newUser->created = date('Y-m-d H:i:s'); $newUser->update(); } $ext = new Model\Extension(array('acl' => $this->project->getService('acl'))); $ext->getModules($this->project); if (count($ext->new) > 0) { $ext->installModules(); } $user->set('form', ' <p style="text-align: center; margin: 50px 0 0 0; line-height: 1.8em; font-size: 1.2em;">' . $this->i18n->__('Thank you. The system has been successfully installed.') . '<br />' . $this->i18n->__('You can now log in %1here%2 or view the home page %3here%4.', array('<a href="' . BASE_PATH . APP_URI . '/login">', '</a>', '<a href="' . BASE_PATH . '/" target="_blank">', '</a>')) . '</p>' . PHP_EOL); Model\Install::send($form); unset($this->sess->config); unset($this->sess->app_uri); $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData()); $this->view->set('i18n', $this->i18n); $this->send(); } else { $user->set('form', $form); $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData()); $this->view->set('i18n', $this->i18n); $this->send(); } } else { $user->set('form', $form); $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData()); $this->view->set('i18n', $this->i18n); $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()); } } }