Exemplo 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;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
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);
     if ($_POST) {
         if ($this->id == 2001) {
             $this->getElement('type')->addValidator(new Validator\Equal('user', $this->i18n->__("The type name for this user type cannot change and must be 'user'.")));
         }
     }
     $this->checkFiles();
     return $this;
 }
Exemplo n.º 4
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);
     if ($_POST) {
         if (strpos($this->type, 'history') !== false && $this->group_id != '0') {
             $this->getElement('group_id')->addValidator(new Validator\NotEqual($this->group_id, $this->i18n->__('A field with history tracking cannot be assigned to a field group.')));
         }
         if ($this->editor != 'source' && $this->group_id != '0') {
             $this->getElement('group_id')->addValidator(new Validator\NotEqual($this->group_id, $this->i18n->__('An editor cannot be used on a field assigned to a field group.')));
         }
     }
 }
Exemplo n.º 5
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);
     if ($_POST) {
         if (Validator\Email::factory()->evaluate($this->email)) {
             $user = Table\Users::findBy(array('email' => $this->email));
             if (!isset($user->id)) {
                 $this->getElement('email')->addValidator(new Validator\NotEqual($this->email, $this->i18n->__('That email does not exist.')));
             }
         }
     }
     return $this;
 }
Exemplo n.º 6
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 validator for checking ftp connection
     if ($_POST) {
         try {
             $ftp = @new \Pop\Ftp\Ftp($this->ftp_address, $this->username, $this->password, (bool) $this->protocol);
         } catch (\Exception $e) {
             $this->getElement('ftp_address')->addValidator(new Validator\NotEqual($this->ftp_address, $e->getMessage()));
         }
     }
     return $this;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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);
     $this->checkFiles();
     return $this;
 }