コード例 #1
0
 /**
  * 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();
             }
         }
     }
 }
コード例 #2
0
ファイル: IndexController.php プロジェクト: phirecms/phirecms
 /**
  * Register action method
  *
  * @param  int $id
  * @return void
  */
 public function register($id)
 {
     $role = new Model\Role();
     if ($role->canRegister($id)) {
         $this->prepareView('phire/register.phtml');
         $this->view->title = 'Register';
         $captcha = isset($this->application->config()['registration_captcha']) && $this->application->config()['registration_captcha'];
         $csrf = isset($this->application->config()['registration_csrf']) && $this->application->config()['registration_csrf'];
         $role->getById($id);
         if ($role->email_as_username) {
             $fields = $this->application->config()['forms']['Phire\\Form\\RegisterEmail'];
             $fields[2]['role_id']['value'] = $id;
             $this->view->form = new Form\RegisterEmail($captcha, $csrf, $fields);
         } else {
             $fields = $this->application->config()['forms']['Phire\\Form\\Register'];
             $fields[2]['role_id']['value'] = $id;
             if ($role->email_required) {
                 $fields[1]['email']['required'] = true;
             }
             $this->view->form = new Form\Register($captcha, $csrf, $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();
                 $role->getById($id);
                 $fields['active'] = (int) (!$role->approval);
                 $fields['verified'] = (int) (!$role->verification);
                 $user = new Model\User();
                 $user->save($fields);
                 $this->view->id = $user->id;
                 $this->view->success = true;
                 $this->view->verified = $user->verified;
             }
         }
         $this->send();
     } else {
         $this->redirect(BASE_PATH . (APP_URI != '' ? APP_URI : '/'));
     }
 }
コード例 #3
0
 /**
  * Register method
  *
  * @param  string $redirect
  * @return void
  */
 public function register($redirect = null)
 {
     // If registration is not allowed
     if (!$this->type->registration) {
         Response::redirect($this->request->getBasePath());
         // Else render the registration form
     } else {
         $this->prepareView('register.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->__('Register'));
         $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $this->type->id, true, 0, null, true);
         // 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 = new Model\User();
                 $user->save($form, $this->project->module('Phire'));
                 if (null !== $redirect) {
                     Response::redirect($redirect);
                 } else {
                     $this->view->set('form', '        <h4>Thank you for registering.</h4>')->set('typeUri', strtolower($this->type->type) != 'user' ? '/' . strtolower($this->type->type) : APP_URI);
                     if ($this->type->verification) {
                         $this->view->set('verify', true);
                     }
                     if ($this->type->approval) {
                         $this->view->set('approval', true);
                     }
                     $this->send();
                 }
                 // Else, re-render the form with errors
             } else {
                 $this->view->set('form', $form);
                 $this->send();
             }
             // Else, render the form
         } else {
             $this->view->set('form', $form);
             $this->send();
         }
     }
 }
コード例 #4
0
 /**
  * User add method
  *
  * @return void
  */
 public function add()
 {
     $this->prepareView('add.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav')));
     // Select user type
     if (null === $this->request->getPath(1)) {
         $this->view->set('title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Select Type'));
         $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', '0', false, 0, $this->project->getService('acl'));
         // 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, redirect to the second part of the form
             if ($form->isValid()) {
                 Response::redirect($this->request->getBasePath() . $this->request->getRequestUri() . '/' . $form->type_id);
                 // Else, re-render the form with errors
             } else {
                 $this->view->set('form', $form);
                 $this->send();
             }
             // Else, render the form
         } else {
             $this->view->set('form', $form);
             $this->send();
         }
         // Else, add user
     } else {
         $type = Table\UserTypes::findById($this->request->getPath(1));
         // If user type is valid
         if (isset($type->id)) {
             $this->view->set('title', $this->view->i18n->__('Users') . ' ' . $this->view->separator . ' ' . ucwords(str_replace('-', ' ', $type->type)) . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Add'))->set('typeId', $type->id);
             $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $type->id, false, 0);
             // 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 new user
                 if ($form->isValid()) {
                     $user = new Model\User();
                     $user->save($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('redirect' => $this->request->getBasePath() . '/edit/' . $user->id . '?saved=' . time(), 'updated' => '', 'form' => 'user-form'));
                         } else {
                             Response::redirect($this->request->getBasePath() . '/index/' . $this->request->getPath(1) . '?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 form
             } else {
                 $this->view->set('form', $form);
                 $this->send();
             }
             // Else, redirect
         } else {
             Response::redirect($this->request->getBasePath() . '/add');
         }
     }
 }
コード例 #5
0
 /**
  * Add action method
  *
  * @return void
  */
 public function add()
 {
     $roleId = $this->getRoleId();
     $username = '';
     $email = null;
     $role = new Model\Role();
     $role->getById($roleId);
     $this->console->write();
     $dupeUser = Table\Users::findBy(['username' => $username]);
     while ($username == '' || isset($dupeUser->id)) {
         if (isset($dupeUser->id)) {
             $this->console->write($this->console->colorize('That username already exists.', Console::BOLD_RED));
             $username = '';
         }
         if ($role->email_as_username) {
             while (!(new Email())->evaluate($username)) {
                 $username = $this->console->prompt($this->console->getIndent() . 'Enter Email: ');
             }
             $email = $username;
         } else {
             while ($username == '') {
                 $username = $this->console->prompt($this->console->getIndent() . 'Enter Username: '******'';
                 while (!(new Email())->evaluate($email)) {
                     $email = $this->console->prompt($this->console->getIndent() . 'Enter Email: ');
                 }
             }
         }
         $dupeUser = Table\Users::findBy(['username' => $username]);
     }
     $password = '';
     while ($password == '') {
         $password = $this->console->prompt($this->console->getIndent() . 'Enter Password: '******'';
     while (strtolower($active) != 'y' && strtolower($active) != 'n') {
         $active = $this->console->prompt($this->console->getIndent() . 'Active? (Y/N): ');
     }
     $verified = '';
     while (strtolower($verified) != 'y' && strtolower($verified) != 'n') {
         $verified = $this->console->prompt($this->console->getIndent() . 'Verified? (Y/N): ');
     }
     $fields = ['role_id' => $roleId, 'username' => $username, 'password1' => $password, 'email' => $email, 'active' => strtolower($active) == 'y' ? 1 : 0, 'verified' => strtolower($verified) == 'y' ? 1 : 0];
     $user = new Model\User();
     $user->save($fields);
     $this->console->write();
     $this->console->write($this->console->colorize('User Added!', Console::BOLD_GREEN));
 }
コード例 #6
0
ファイル: IndexController.php プロジェクト: phirecms/phirecms
 /**
  * Add action method
  *
  * @param  int $rid
  * @return void
  */
 public function add($rid = null)
 {
     $this->prepareView('phire/users/add.phtml');
     $this->view->title = 'Add User';
     if (null !== $rid && $this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $rid, 'add')) {
         $role = new Model\Role();
         $role->getById($rid);
         $this->view->title .= ' : ' . $role->name;
         if ($role->email_as_username) {
             $fields = $this->application->config()['forms']['Phire\\Form\\UserEmail'];
         } else {
             $fields = $this->application->config()['forms']['Phire\\Form\\User'];
             if ($role->email_required) {
                 $fields[2]['email']['required'] = true;
             }
         }
         $fields[1]['password1']['required'] = true;
         $fields[1]['password2']['required'] = true;
         $fields[0]['role_id']['value'] = $rid;
         $this->view->form = $role->email_as_username ? new Form\UserEmail($fields) : new Form\User($fields);
         if ($this->request->isPost()) {
             $this->view->form->addFilter('strip_tags', null, 'textarea')->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->save($this->view->form->getFields());
                 $this->view->id = $user->id;
                 $this->sess->setRequestValue('saved', true);
                 $this->redirect(BASE_PATH . APP_URI . '/users/edit/' . $user->id);
             }
         }
     } else {
         $this->view->roles = (new Model\Role())->getAll();
     }
     $this->send();
 }
コード例 #7
0
ファイル: IndexController.php プロジェクト: phirecms/phirecms
 /**
  * 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();
 }