/** * Validates an array of fields. Returns the field names and values, with * the field names stripped of their validators. * * The key names can be in this format: * * name:validator=param:anotherValidator:oneMoreValidator=`param` * * @access public * @param LoginDictionary $dictionary The fields to validate. * @param string $validationFields * @return array An array of field name => value pairs. */ public function validateFields(LoginDictionary $dictionary, $validationFields = '') { $keys = $dictionary->toArray(); $this->fields = $keys; /* process the list of fields that will be validated */ $validationFields = explode(',', $validationFields); $fieldValidators = array(); foreach ($validationFields as $idx => $v) { $v = trim(ltrim($v), ' '); /* allow multi-line definitions */ $key = explode(':', $v); /* explode into list separated by : */ if (!empty($key[0])) { $field = $key[0]; array_splice($key, 0, 1); /* remove the field name from validator list */ $fieldValidators[$field] = $key; if (!isset($this->fields[$field]) && strpos($field, '.') === false) { /* prevent someone from bypassing a required field by removing it from the form */ $keys[$field] = !empty($this->fields[$v]) ? $this->fields[$v] : ''; } } } /** @var string|array $v */ foreach ($keys as $k => $v) { /* is a array field, ie contact[name] */ if (is_array($v) && !isset($_FILES[$k]) && is_string($k) && intval($k) == 0 && $k !== 0) { $isCheckbox = false; foreach ($v as $key => $val) { if (!is_string($key)) { $isCheckbox = true; continue; } $subKey = $k . '.' . $key; $this->_validate($subKey, $val, $fieldValidators); } if ($isCheckbox) { $this->_validate($k, $v, $fieldValidators); } } else { $this->_validate($k, $v, $fieldValidators); } } /* remove fields that have . in name */ foreach ($this->fields as $field => $v) { if (strpos($field, '.') !== false || strpos($field, ':')) { unset($this->fields[$field]); } } /* add fields back into dictionary */ foreach ($this->fields as $k => $v) { $dictionary->set($k, $v); } return $this->fields; }
/** * Load the Dictionary class * @return LoginDictionary */ public function loadDictionary() { $classPath = $this->getProperty('dictionaryClassPath', $this->login->config['modelPath'] . 'login/'); $className = $this->getProperty('dictionaryClassName', 'LoginDictionary'); if ($this->modx->loadClass($className, $classPath, true, true)) { $this->dictionary = new LoginDictionary($this->login); $this->dictionary->gather(); } else { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Login] Could not load LoginDictionary class from '); } return $this->dictionary; }
/** * Run any post-logout hooks * * @param modProcessorResponse $response * @return boolean */ public function runPostLogoutHooks(modProcessorResponse $response) { $success = true; /* do post hooks for logout */ $postHooks = $this->getProperty('postHooks', ''); $this->loadHooks('postHooks'); $fields = $this->dictionary->toArray(); $fields['response'] =& $response->getObject(); $fields['contexts'] =& $contexts; $fields['loginContext'] =& $loginContext; $fields['logoutResourceId'] =& $logoutResourceId; $this->postHooks->loadMultiple($postHooks, $fields, array('mode' => Login::MODE_LOGOUT)); /* log posthooks errors */ if ($this->postHooks->hasErrors()) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Login] Post-Hook errors: ' . print_r($this->postHooks->getErrors(), true)); $errorMsg = $this->postHooks->getErrorMessage(); if (!empty($errorMsg)) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Login] Post-Hook error: ' . $errorMsg); } $success = false; } return $success; }