/** * Get user session data * * @param int $id * @return array */ public function getUserData($id) { $user = \Phire\Table\Users::findById($id); $userData = Table\UserSessionData::findById($id); if (isset($userData->user_id)) { $data = $userData->getColumns(); if (null !== $data['logins']) { $this->data['logins'] = unserialize($data['logins']); krsort($this->data['logins']); } $this->data['total_logins'] = (int) $data['total_logins']; $this->data['failed_attempts'] = $data['failed_attempts']; } else { $this->data['logins'] = []; $this->data['total_logins'] = 0; $this->data['failed_attempts'] = 0; } $this->data['username'] = $user->username; $this->data['user_id'] = $id; }
/** * 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(); } } } }
/** * Remove user * * @param array $post * @return void */ public function remove(array $post) { if (isset($post['remove_users'])) { foreach ($post['remove_users'] as $id) { $user = Table\Users::findById($id); if (isset($user->id)) { $user->delete(); } FieldValue::remove($id); } } }
/** * Verify a user * * @param int $id * @param string $hash * @return boolean */ public function verify($id, $hash) { $result = false; $user = Table\Users::findById((int) $id); if (isset($user->id) && $hash == sha1($user->email)) { $user->verified = 1; $user->save(); $this->data['id'] = $user->id; $result = true; } return $result; }
/** * User logins method * * @return void */ public function logins() { if (null === $this->request->getPath(1)) { Response::redirect($this->request->getBasePath()); } else { if ($this->request->isPost()) { $user = Table\Users::findById($this->request->getPath(1)); if (isset($user->id)) { $user->logins = null; $user->update(); } $typeId = null !== $this->request->getQuery('type_id') ? '/index/' . $this->request->getQuery('type_id') : null; Response::redirect($this->request->getBasePath() . $typeId); } else { $this->prepareView('logins.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'))); $user = new Model\User(); $user->getLoginsById($this->request->getPath(1)); $this->view->set('title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . $user->type_name . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Logins') . ' ' . $this->view->separator . ' ' . $user->username)->set('typeId', $user->type_id)->set('table', $user->table); $this->send(); } } }
/** * Remove sites * * @param array $post * @return void */ public function remove(array $post) { if (isset($post['remove_sites'])) { foreach ($post['remove_sites'] as $id) { $site = Table\Sites::findById($id); if (isset($site->id)) { $users = Table\Users::findAll(); foreach ($users->rows as $user) { $siteIds = unserialize($user->site_ids); if (in_array($site->id, $siteIds)) { $key = array_search($site->id, $siteIds); unset($siteIds[$key]); $u = Table\Users::findById($user->id); if (isset($u->id)) { $u->site_ids = serialize($siteIds); $u->update(); } } } $site->delete(); } } } }
/** * Get content * * @param array $data * @return array */ protected function setContent(array $data) { $type = new ContentType(); $type->getById($data['type_id']); $data['content_type'] = $type->content_type; $data['content_type_force_ssl'] = $type->force_ssl; $data['strict_publishing'] = $type->strict_publishing; if (!empty($data['publish'])) { $publish = explode(' ', $data['publish']); $data['publish_date'] = $publish[0]; $data['publish_time'] = $publish[1]; if (isset($this->date_format)) { $data['publish_date'] = date($this->date_format, strtotime($data['publish_date'])); } if (isset($this->time_format)) { $data['publish_time'] = date($this->time_format, strtotime($data['publish_time'])); } } if (!empty($data['expire'])) { $expire = explode(' ', $data['expire']); $data['expire_date'] = $expire[0]; $data['expire_time'] = $expire[1]; if (isset($this->date_format)) { $data['expire_date'] = date($this->date_format, strtotime($data['expire_date'])); } if (isset($this->time_format)) { $data['expire_time'] = date($this->time_format, strtotime($data['expire_time'])); } } if (!empty($content->created_by)) { $createdBy = \Phire\Table\Users::findById($content->created_by); if (isset($createdBy->id)) { $data['created_by_username'] = $createdBy->username; } } if (!empty($content->updated_by)) { $updatedBy = \Phire\Table\Users::findById($content->updated_by); if (isset($updatedBy->id)) { $data['updated_by_username'] = $updatedBy->username; } } $data['content_parent_id'] = $data['parent_id']; $data['content_status'] = $data['status']; $data['content_template'] = $data['template']; $data['breadcrumb'] = $this->getBreadcrumb($data['id'], null !== $this->separator ? $this->separator : '>'); $data['breadcrumb_text'] = strip_tags($data['breadcrumb'], 'span'); if (!is_array($data['roles']) && is_string($data['roles'])) { $data['roles'] = unserialize($data['roles']); } $this->data = array_merge($this->data, $data); return $this->data; }
/** * Set the field values * * @param array $values * @param array $filters * @param \Pop\Config $config * @return \Pop\Form\Form */ public function setFieldValues(array $values = null, $filters = null, $config = null) { parent::setFieldValues($values, $filters); if ($this->id != 0) { if (null !== $this->getElement('email2')) { $this->getElement('email2')->setRequired(false); } if (null !== $this->getElement('password1') && null === $this->reset_pwd) { $this->getElement('password1')->setRequired(false); $this->getElement('password2')->setRequired(false); } } // Add validators for checking dupe usernames // and matching the emails and passwords if ($_POST && isset($_POST['id'])) { if (isset($this->fields['username'])) { $username = $this->username; $usernameField = 'username'; } else { $username = $this->email1; $usernameField = 'email1'; } $user = Table\Users::findBy(array('username' => $username)); if (isset($user->id) && $this->id != $user->id) { $this->getElement($usernameField)->addValidator(new Validator\NotEqual($username, $this->i18n->__('That user already exists.'))); } $email = Table\Users::findBy(array('email' => $this->email1)); if (isset($email->id) && $this->id != $email->id) { $this->getElement('email1')->addValidator(new Validator\NotEqual($this->email1, $this->i18n->__('That email already exists.'))); } if (null !== $this->getElement('email2')) { $this->getElement('email2')->addValidator(new Validator\Equal($this->email1, $this->i18n->__('The emails do not match.'))); } // If the password fields are set, check them for a match if (isset($this->password2)) { $this->getElement('password2')->addValidator(new Validator\Equal($this->password1, $this->i18n->__('The passwords do not match.'))); } if ($this->reset_pwd) { $user = Table\Users::findById($this->id); if (isset($user->id)) { $curPassword = $user->password; $type = Table\UserTypes::findById($user->type_id); if (isset($type->id)) { $encOptions = $config->encryptionOptions->asArray(); $auth = new \Pop\Auth\Adapter\Table('Phire\\Table\\Users'); $result = $auth->authenticate($this->username, $this->password2, $type->password_encryption, $encOptions); if ($result != \Pop\Auth\Auth::PASSWORD_INCORRECT) { $this->getElement('password2')->addValidator(new Validator\Equal($curPassword, $this->i18n->__('The new password cannot be the same.'))); } } } } } $this->checkFiles(); return $this; }