Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @param  array $filters
  * @return \Pop\Form\Form
  */
 public function setFieldValues(array $values = null, $filters = null)
 {
     parent::setFieldValues($values, $filters);
     // Add validators for checking dupe names and devices
     if ($_POST && isset($_POST['id'])) {
         $site = Table\Sites::findBy(array('domain' => $this->domain));
         if (isset($site->id) && $this->id != $site->id || $this->domain == $_SERVER['HTTP_HOST']) {
             $this->getElement('domain')->addValidator(new Validator\NotEqual($this->domain, $this->i18n->__('That site domain already exists.')));
         }
         $site = Table\Sites::findBy(array('document_root' => $this->document_root));
         if (isset($site->id) && $this->id != $site->id) {
             $this->getElement('document_root')->addValidator(new Validator\NotEqual($this->document_root, $this->i18n->__('That site document root already exists.')));
         }
         $docRoot = substr($this->document_root, -1) == '/' || substr($this->document_root, -1) == "\\" ? substr($this->document_root, 0, -1) : $this->document_root;
         if ($this->base_path != '') {
             $basePath = substr($this->base_path, 0, 1) != '/' || substr($this->base_path, 0, 1) != "\\" ? '/' . $this->base_path : $this->base_path;
             if (substr($basePath, -1) == '/' || substr($basePath, -1) == "\\") {
                 $basePath = substr($basePath, 0, -1);
             }
         } else {
             $basePath = '';
         }
         if (!file_exists($docRoot)) {
             $this->getElement('document_root')->addValidator(new Validator\NotEqual($this->document_root, $this->i18n->__('That site document root does not exists.')));
         } else {
             if (!file_exists($docRoot . $basePath)) {
                 $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The base path does not exist under that document root.')));
             } else {
                 if (!file_exists($docRoot . $basePath . DIRECTORY_SEPARATOR . 'index.php')) {
                     $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The index controller does not exist under that document root and base path.')));
                 } else {
                     if (!file_exists($docRoot . $basePath . DIRECTORY_SEPARATOR . CONTENT_PATH)) {
                         $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The content path does not exist under that document root and base path.')));
                     } else {
                         if (!is_writable($docRoot . $basePath . DIRECTORY_SEPARATOR . CONTENT_PATH)) {
                             $this->getElement('base_path')->addValidator(new Validator\NotEqual($this->base_path, $this->i18n->__('The content path is not writable under that document root and base path.')));
                         }
                     }
                 }
             }
         }
     }
     $this->checkFiles();
     return $this;
 }
Ejemplo n.º 3
0
 /**
  * Static method to get base configuration values
  *
  * @return \ArrayObject
  */
 public static function getSystemConfig()
 {
     $settings = array('system_title', 'system_email', 'reply_email', 'site_title', 'separator', 'default_language', 'datetime_format', 'media_allowed_types', 'media_max_filesize', 'media_actions', 'media_image_adapter', 'pagination_limit', 'pagination_range', 'force_ssl', 'live');
     $config = array();
     $cfg = static::findAll();
     foreach ($cfg->rows as $c) {
         if (in_array($c->setting, $settings)) {
             $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? unserialize($c->value) : $c->value;
         }
     }
     $allowedTypes = Model\Config::getMediaTypes();
     foreach ($allowedTypes as $key => $value) {
         if (!in_array($key, $config['media_allowed_types'])) {
             unset($allowedTypes[$key]);
         }
     }
     if ($config['media_max_filesize'] > 999999) {
         $maxSize = round($config['media_max_filesize'] / 1000000) . ' MB';
     } else {
         if ($config['media_max_filesize'] > 999) {
             $maxSize = round($config['media_max_filesize'] / 1000) . ' KB';
         } else {
             $maxSize = $config['media_max_filesize'] . ' B';
         }
     }
     $config['media_max_filesize_formatted'] = $maxSize;
     $config['media_allowed_types'] = $allowedTypes;
     $site = Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     if (isset($site->id)) {
         $config['site_title'] = $site->title;
         $config['base_path'] = $site->base_path;
         $config['force_ssl'] = $site->force_ssl;
         $config['live'] = $site->live;
     } else {
         $config['base_path'] = BASE_PATH;
     }
     return new \ArrayObject($config, \ArrayObject::ARRAY_AS_PROPS);
 }
Ejemplo n.º 4
0
 /**
  * Login method
  *
  * @param  string $redirect
  * @return void
  */
 public function login($redirect = null)
 {
     $site = Table\Sites::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     // Prevent attempting to log into the system from other sites
     if (isset($site->id) && strtolower($this->type->type) == 'user') {
         Response::redirect('http://' . $site->domain . BASE_PATH);
         // If user type is not found, 404
     } else {
         if (!isset($this->type->id)) {
             $this->error();
             // If login is not allowed
         } else {
             if (!$this->type->login) {
                 Response::redirect(BASE_PATH . '/');
                 // Else, render the form
             } else {
                 $this->prepareView('login.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->__('Login'));
                 // Set up 'forgot,' 'register' and 'unsubscribe' links
                 $uri = strtolower($this->type->type) == 'user' ? APP_URI : '/' . strtolower($this->type->type);
                 $forgot = '<a href="' . BASE_PATH . $uri . '/forgot">' . $this->view->i18n->__('Forgot') . '</a>';
                 $forgot .= $this->type->registration ? ' | <a href="' . BASE_PATH . $uri . '/register">' . $this->view->i18n->__('Register') . '</a>' : null;
                 $forgot .= !$this->type->unsubscribe_login ? ' | <a href="' . BASE_PATH . $uri . '/unsubscribe">' . $this->view->i18n->__('Unsubscribe') . '</a>' : null;
                 $this->view->set('forgot', $forgot);
                 if (isset($this->sess->expired)) {
                     $this->view->set('error', $this->view->i18n->__('Your session has expired.'));
                 } else {
                     if (isset($this->sess->authError)) {
                         $this->view->set('error', $this->view->i18n->__('The user is not allowed in this area.'));
                     }
                 }
                 $form = new Form\Login($this->request->getBasePath() . $this->request->getRequestUri(), 'post');
                 // If form is submitted
                 if ($this->request->isPost()) {
                     $user = new Model\User();
                     $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')), $this->project->getService('auth')->config($this->type, $this->request->getPost('username')), $this->type, $user);
                     $this->view->set('form', $form);
                     // If form is valid, authenticate the user
                     if ($form->isValid()) {
                         $user->login($form->username, $this->type);
                         if (isset($this->sess->lastUrl)) {
                             $url = $this->sess->lastUrl;
                         } else {
                             $url = null !== $redirect ? $redirect : $this->request->getBasePath();
                         }
                         unset($this->sess->expired);
                         unset($this->sess->authError);
                         unset($this->sess->lastUrl);
                         if ($url == '') {
                             $url = '/';
                         }
                         Response::redirect($url);
                         // Else, re-render the form
                     } else {
                         $this->send();
                     }
                     // Else, render the form
                 } else {
                     $this->view->set('form', $form);
                     $this->send();
                 }
             }
         }
     }
 }