function display($tpl = null) { $app = JFactory::getApplication(); $input = JFactory::getApplication()->input; $provider = $input->getCmd('provider', null); if (!$provider) { $app->redirect('index.php'); } $provider = JFBCFactory::provider($provider); $providerUserId = $provider->getProviderUserId(); $profile = $provider->profile->fetchProfile($providerUserId, array('first_name', 'last_name', 'email', 'full_name')); if ($providerUserId == null) { $app->redirect('index.php'); } $args = array(strtolower($provider->name)); $profileFields = $app->triggerEvent('socialProfilesOnShowRegisterForm', $args); // Get previously filled in values $postData = $app->getUserState('com_jfbconnect.registration.data', array()); $email1 = ''; $email2 = ''; SCUserUtilities::getDisplayEmail($postData, $profile->get('email'), $email1, $email2); $config = JFBCFactory::config(); $providerUsername = ''; $postUsername = SCUserUtilities::getPostData($postData, 'username'); if ($postUsername != '') { $providerUsername = $postUsername; } else { if (JFBCFactory::config()->get('registration_show_username') > USERNAME_LEAVE_BLANK) { $usernamePrefixFormat = $config->get('auto_username_format'); $providerUsername = SCUserUtilities::getAutoUsername($profile->get('first_name'), $profile->get('last_name'), $profile->get('email'), $provider->usernamePrefix, $providerUserId, $usernamePrefixFormat); } } $providerMemberName = SCUserUtilities::getDisplayNameByFullName($postData, $profile->get('full_name')); $language = JFactory::getLanguage(); $language->load('com_users'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_users/models'); $userModel = JModelLegacy::getInstance('Registration', 'UsersModel'); $this->data = $userModel->getData(); JForm::addFormPath(JPATH_SITE . '/components/com_users/models/forms'); JForm::addFieldPath(JPATH_SITE . '/components/com_users/models/fields'); $this->form = $userModel->getForm(); // Setup the fields we can pre-populate // To do: Give option to show/hide the name on the form $this->form->setValue('name', null, $providerMemberName); if ($config->get('registration_show_name') == NAME_HIDE && $providerMemberName != '') { $this->form->setFieldAttribute('name', 'type', 'hidden'); } $this->form->setValue('username', null, $providerUsername); if ($providerUsername != '') { if ($config->get('registration_show_username') == USERNAME_GENERATE_HIDE) { $this->form->setFieldAttribute('username', 'type', 'hidden'); } else { if ($config->get('registration_show_username') == USERNAME_GENERATE_DISABLE) { $this->form->setFieldAttribute('username', 'readonly', 'true'); } } } $this->form->setValue('email1', null, $email1); $this->form->setValue('email2', null, $email2); if ($email1 != '' && $email2 != '') { if ($config->get('registration_show_email') == EMAIL_HIDE) { $this->form->setFieldAttribute('email1', 'type', 'hidden'); $this->form->setFieldAttribute('email2', 'type', 'hidden'); } else { if ($config->get('registration_show_email') == EMAIL_SHOW_DISABLE) { $this->form->setFieldAttribute('email1', 'readonly', 'true'); $this->form->setFieldAttribute('email2', 'readonly', 'true'); } } } if ($config->get('registration_show_password') == 1) { $password = JUserHelper::genRandomPassword(); $this->form->setValue('password1', null, $password); $this->form->setValue('password2', null, $password); $this->form->setFieldAttribute('password1', 'type', 'hidden'); $this->form->setFieldAttribute('password2', 'type', 'hidden'); } // Set an inputbox style on all the input elements so that inherited template styles look better $this->form->setFieldAttribute('name', 'class', 'inputbox required'); $this->form->setFieldAttribute('username', 'class', 'validate-username inputbox required'); $this->form->setFieldAttribute('email1', 'class', 'inputbox required'); $this->form->setFieldAttribute('email2', 'class', 'inputbox required'); $this->form->setFieldAttribute('password1', 'class', 'validate-password inputbox required'); $this->form->setFieldAttribute('password2', 'class', 'validate-password inputbox required'); //Check for form validation from each of the plugins $areProfilesValidating = $app->triggerEvent('socialProfilesAddFormValidation'); $defaultValidationNeeded = true; foreach ($areProfilesValidating as $hasDoneValidation) { if ($hasDoneValidation == true) { $defaultValidationNeeded = false; break; } } // Setup the view appearance // TODO: Make the addStyleSheet into a Utilities function to be used elsewhere. $displayType = $config->get('registration_display_mode'); $css = JPath::find($this->_path['template'], 'loginregister.css'); $css = str_replace(JPATH_SITE, '', $css); $css = JURI::root() . $css; $css = str_replace('\\', "/", $css); //Windows support for file separators $doc = JFactory::getDocument(); $doc->addStyleSheet($css); // get the other providers, for showing their login buttons $altParams = array(); $allProviders = JFBCFactory::getAllProviders(); $altProviders = array(); foreach ($allProviders as $p) { if ($p->name != $provider->name) { $altParams['providers'][] = $p->systemName; } } $altParams['image'] = 'icon.png'; // Set the session bit to check for a new login on next page load SCSocialUtilities::setJFBCNewMappingEnabled(); $this->altParams = $altParams; $this->assignRef('providerUserId', $providerUserId); $this->assignRef('profile', $profile); $this->assignRef('configModel', $config); $this->assignRef('profileFields', $profileFields); $this->assignRef('defaultValidationNeeded', $defaultValidationNeeded); $this->assignRef('displayType', $displayType); $this->assignRef('providerName', $provider->name); $this->assignRef('altProviders', $altProviders); parent::display($tpl); }
function autoCreateUser($providerUserId, $provider) { $provider->setInitialRegistration(); $profile = $provider->profile->fetchProfile($providerUserId, array('first_name', 'last_name', 'email', 'full_name')); if ($profile == null || $profile->get('email') == null) { # not enough information returned to auto-create account return false; } $newEmail = $profile->get('email'); $fullname = $profile->get('full_name'); $user['fullname'] = $fullname; $user['email'] = $newEmail; // Create random password for FB User Only, but save so we can email to the user on account creation if (JFBCFactory::config()->getSetting('generate_random_password')) { $this->_newUserPassword = JUserHelper::genRandomPassword(); $user['password_clear'] = $this->_newUserPassword; // Check for Joomla 3.2.1's new hashPassword functions and use those, if exist if (method_exists('JUserHelper', 'hashPassword')) { $user['password'] = JUserHelper::hashPassword($this->_newUserPassword); } else { $salt = JUserHelper::genRandomPassword(32); $crypt = JUserHelper::getCryptedPassword($this->_newUserPassword, $salt); $user['password'] = $crypt . ':' . $salt; } } else { $user['password_clear'] = ""; $this->_newUserPassword = ''; } $lang = JRequest::getVar(JApplication::getHash('language'), '', 'COOKIE'); $user['language'] = $lang; $usernamePrefixFormat = JFBCFactory::config()->getSetting('auto_username_format'); $username = SCUserUtilities::getAutoUsername($profile->get('first_name'), $profile->get('last_name'), $profile->get('email'), $provider->usernamePrefix, $providerUserId, $usernamePrefixFormat); $user['username'] = $username; $useractivation = $this->getActivationMode(); $jUser = $this->getBlankUser($user, $useractivation); if ($jUser && $jUser->get('id', null)) { $this->onAfterRegister($provider, $jUser); SCSocialUtilities::clearJFBCNewMappingEnabled(); if (JFBCFactory::usermap()->map($jUser->get('id'), $providerUserId, $provider->systemName, $provider->client->getToken())) { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_SUCCESS', $provider->name)); return true; } else { JFBCFactory::log(JText::sprintf('COM_JFBCONNECT_MAP_USER_FAIL', $provider->name)); } } return false; // User creation failed for some reason }
protected function getAutoUsername($providerProfile) { $usernamePrefixFormat = JFBCFactory::config()->getSetting('auto_username_format'); $provider = $this->network; $providerPrefix = "__"; if ($provider == 'facebook') { $providerPrefix = "fb_"; } else { if ($provider == "google") { $providerPrefix = "g_"; } else { if ($provider == "twitter") { $providerPrefix = "t_"; } } } return SCUserUtilities::getAutoUsername($providerProfile->get('first_name'), $providerProfile->get('last_name'), $providerProfile->get('email'), $providerPrefix, $this->socialId, $usernamePrefixFormat); }