/** * Injects several fields into specific forms. * * @param JForm $form The form to be altered. * @param array $data The associated data for the form. * * @return boolean * * @since 2.0 */ public function onContentPrepareForm($form, $data) { // Check we are manipulating a valid form if (!$form instanceof JForm) { $this->_subject->setError('JERROR_NOT_A_FORM'); return false; } // Check if the password field needs injecting if ($this->params->get('use_ldap_password', false) && in_array($form->getName(), $this->passwordForms)) { // Check if this user should have a profile if (SHLdapHelper::isUserLdap(isset($data->id) ? $data->id : 0)) { if ($this->params->get('ldap_password_layout_edit', true)) { // Check if this is in the 'edit' layout or in the save state if (strtolower(JFactory::getApplication()->input->get('layout')) === 'edit' || strtolower(JFactory::getApplication()->input->get('task')) === 'save') { $form->loadFile(realpath(__DIR__) . '/forms/ldap_password.xml', false, false); } } else { $form->loadFile(realpath(__DIR__) . '/forms/ldap_password.xml', false, false); } } } // Check if the domain field needs injecting if ($this->params->get('use_ldap_domain', false) && in_array($form->getName(), $this->domainForms)) { $form->loadFile(realpath(__DIR__) . '/forms/ldap_domain.xml', false, false); } return true; }
/** * Method is called on user login failure. * * @param array $response The authentication response. * * @return void * * @since 2.0 */ public function onUserLoginFailure($response) { // Check if the attempted login was an Ldap user, if so then fire the event if ($username = SHUtilArrayhelper::getValue($response, 'username', false, 'string')) { // Check if the user exists in the J! database if ($id = JUserHelper::getUserId($username)) { if (SHLdapHelper::isUserLdap($id)) { SHLdapHelper::triggerEvent('onUserLoginFailure', array($response)); } } } }
/** * Loads the profile XML and passes it to the form to load the fields (excluding data). * * @param JForm $form The form to be altered. * @param array $data The associated data for the form. * * @return boolean * * @since 2.0 */ public function onContentPrepareForm($form, $data) { // Check if the profile parameter is enabled if (!$this->use_profile) { return true; } if (!($form instanceof JForm)) { $this->_subject->setError('JERROR_NOT_A_FORM'); return false; } // Check we are manipulating a valid form if (!in_array($form->getName(), $this->permittedForms)) { return true; } $showForm = true; $domain = null; // Check if this user should have a profile if ($userId = isset($data->id) ? $data->id : 0) { if (SHLdapHelper::isUserLdap($userId)) { $domain = SHUserHelper::getDomainParam($data); } else { $showForm = false; } } elseif (!JFactory::getUser()->guest) { /* * Sometimes the $data variable is not populated even when an edit is required. * This means we have to check the form post data directly for the user ID. * We do not worry about frontend registrations as we check for guest. * If there is no form posted then this could be a backend registration. */ if ($inForm = JFactory::getApplication()->input->get('jform', false, 'array')) { $id = SHUtilArrayhelper::getValue($inForm, 'id', 0, 'int'); if ($id === 0) { // Ask all plugins if there is a plugin willing to deal with user creation for ldap if (count($results = SHFactory::getDispatcher('ldap')->trigger('askUserCreation'))) { // Due to being unaware of the domain for this new user, we are forced to use the default domain $domain = SHFactory::getConfig()->get('ldap.defaultconfig'); } else { // LDAP creation not enabled $showForm = false; } } else { if (SHLdapHelper::isUserLdap($id)) { // Existing ldap user $domain = SHUserHelper::getDomainParam($id); } else { // Existing non-ldap user $showForm = false; } } } } if ($showForm) { // We have to launch the getxmlfields to correctly include languages $this->getXMLFields($domain); // Get the File and Path for the Profile XML $file = $this->getXMLFileName($domain); $xmlPath = $this->profile_base . '/' . $file . '.xml'; // Load in the profile XML file to the form if (($xml = JFactory::getXML($xmlPath, true)) && ($form->load($xml, false, false))) { // Successfully loaded in the XML return true; } } }