Пример #1
0
 /**
  * Set the field values
  *
  * @param  array                  $values
  * @param  array                  $filters
  * @param  \Phire\Auth\Auth       $auth
  * @param  \Phire\Table\UserTypes $type
  * @param  \Phire\Model\User      $user
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null, $auth = null, $type = null, $user = null)
 {
     parent::setFieldValues($values, $filters);
     if ($_POST) {
         // Authenticate and get the auth result
         $auth->authenticate($this->username, $this->password);
         $result = $auth->getAuthResult($type, $this->username);
         if (null !== $result) {
             $user->login($this->username, $type, false);
             if ($auth->getResult() == \Pop\Auth\Auth::PASSWORD_INCORRECT) {
                 $this->getElement('password')->addValidator(new Validator\NotEqual($this->password, $result));
             } else {
                 $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, $result));
             }
         }
         // Check the user's allowed sites
         if (strtolower($type->type) != 'user') {
             $u = Table\Users::findBy(array('username' => $this->username));
             if (isset($u->id)) {
                 $siteIds = unserialize($u->site_ids);
                 $site = Table\Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
                 $siteId = isset($site->id) ? $site->id : '0';
                 if (!in_array($siteId, $siteIds)) {
                     $this->getElement('username')->addValidator(new Validator\NotEqual($this->username, $this->i18n->__('That user is not allowed on this site.')));
                 }
             }
         }
     }
     return $this;
 }
Пример #2
0
 /**
  * Unsubscribe action method
  *
  * @return void
  */
 public function unsubscribe()
 {
     $this->prepareView('phire/unsubscribe.phtml');
     $this->view->title = 'Unsubscribe';
     $this->view->form = new Form\Unsubscribe($this->application->config()['forms']['Phire\\Form\\Unsubscribe']);
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->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->unsubscribe($this->view->form->getFields());
             $this->view->success = true;
             $this->view->id = $user->id;
             $this->sess->kill();
             $this->redirect(BASE_PATH . APP_URI . '/unsubscribe?success=1');
         }
     }
     $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();
             }
         }
     }
 }
 /**
  * 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());
     }
 }
 /**
  * Export method
  *
  * @return void
  */
 public function export()
 {
     $user = new Model\User();
     $user->getExport($this->request->getPath(1), $this->request->getQuery('sort'), $this->request->getQuery('page'));
     if (isset($user->userRows[0])) {
         $userRows = $user->userRows;
         foreach ($userRows as $key => $value) {
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     $userRows[$key]->{$k} = implode('|', $v);
                 }
             }
         }
         \Pop\Data\Data::factory($userRows)->writeData($_SERVER['HTTP_HOST'] . '_' . $user->userType . '_' . date('Y-m-d') . '.csv', true, true);
     } else {
         Response::redirect($this->request->getBasePath() . '/index/' . $this->request->getPath(1));
     }
 }
Пример #6
0
 /**
  * Remove action method
  *
  * @return void
  */
 public function remove()
 {
     $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: ');
     }
     $user = new Model\User();
     $user->process(['process_users' => [$userId], 'user_process_action' => -1]);
     $this->console->write();
     $this->console->write($this->console->colorize('User Removed!', Console::BOLD_RED));
 }
Пример #7
0
 /**
  * Remove action method
  *
  * @return void
  */
 public function process()
 {
     if ($this->request->isPost()) {
         $user = new Model\User();
         $user->process($this->request->getPost());
     }
     if (null !== $this->request->getPost('user_process_action') && $this->request->getPost('user_process_action') == -1) {
         $this->sess->setRequestValue('removed', true);
     } else {
         $this->sess->setRequestValue('saved', true);
     }
     $this->redirect(BASE_PATH . APP_URI . '/users' . ((int) $this->request->getPost('role_id') != 0 ? '/' . (int) $this->request->getPost('role_id') : null));
 }
Пример #8
0
 /**
  * User action method
  *
  * @return void
  */
 public function user()
 {
     $this->prepareView('phire/install.phtml');
     $this->view->title = 'Install User';
     $fields = $this->application->config()['forms']['Phire\\Form\\Register'];
     $fields[1]['email']['required'] = true;
     $fields[2]['role_id']['value'] = 2001;
     unset($fields[1]['first_name']);
     unset($fields[1]['last_name']);
     unset($fields[1]['company']);
     unset($fields[1]['title']);
     unset($fields[1]['phone']);
     $this->view->form = new Form\Register(false, false, $fields);
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->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();
             $fields['active'] = 1;
             $fields['verified'] = 1;
             $user = new Model\User();
             $user->save($fields);
             $install = new Model\Install();
             $install->sendConfirmation($user);
             $module = new Model\Module();
             if ($module->detectNew()) {
                 $module->install($this->services);
             }
             $dbType = DB_INTERFACE == 'pdo' ? DB_TYPE : DB_INTERFACE;
             if (file_exists(__DIR__ . '/../../../data/install.' . strtolower($dbType) . '.sql')) {
                 $install->installProfile(__DIR__ . '/../../../data/install.' . strtolower($dbType) . '.sql');
             }
             unset($this->sess->config);
             unset($this->sess->app_uri);
             $this->sess->setRequestValue('installed', true);
             $this->redirect(BASE_PATH . APP_URI . '/login');
         }
     }
     $this->send();
 }