/** * Ajax method to update user's authentication via Facebook **/ public function ajaxUpdate() { $response = new JAXResponse(); CFactory::load('libraries', 'facebook'); // Once they reach here, we assume that they are already logged into facebook. // Since CFacebook library handles the security we don't need to worry about any intercepts here. $facebook = new CFacebook(); $connectModel = CFactory::getModel('Connect'); $connectTable =& JTable::getInstance('Connect', 'CTable'); $mainframe =& JFactory::getApplication(); $config = CFactory::getConfig(); $userId = $facebook->getUser(); if (!$userId) { // User really didn't login through Facebook as we can't grab the proper id. $response = $this->_getInvalidResponse($response); $response->sendResponse(); } $connectTable->load($userId); $fields = array('first_name', 'last_name', 'birthday', 'hometown_location', 'status', 'pic', 'sex', 'name', 'pic_square', 'profile_url', 'pic_big'); $userInfo = $facebook->getUserInfo($fields, $userId); //@todo: configurable redirect for continue button $redirect = CRoute::_('index.php?option=com_community&view=profile', false); $error = false; $content = ''; if (!$connectTable->userid) { $tmpl = new CTemplate(); $tmpl->set('userInfo', $userInfo); $content = $tmpl->fetch('facebook.firstlogin'); $buttons = '<input type="button" value="' . JText::_('CC NEXT') . '" class="button" onclick="joms.connect.selectType();" />'; $response->addScriptCall('cWindowResize', 320); $response->addAssign('cWindowContent', 'innerHTML', $content); $response->addScriptCall('joms.jQuery("#cwin_logo").html("' . JText::_('CC ACCOUNT SIGNUP FROM FACEBOOK') . '");'); $response->addScriptCall('cWindowActions', $buttons); $response->sendResponse(); } else { $my = CFactory::getUser($connectTable->userid); CFactory::load('helpers', 'owner'); if (COwnerHelper::isCommunityAdmin($connectTable->userid)) { $tmpl = new CTemplate(); $content = $tmpl->fetch('facebook.link.notallowed'); $buttons = '<input type="button" value="' . JText::_('CC BUTTON CLOSE') . '" class="button" onclick="cWindowHide();" />'; $response->addScriptCall('cWindowActions', $buttons); $response->addAssign('cWindowContent', 'innerHTML', $content); $response->addScriptCall('cWindowResize', 150); return $response->sendResponse(); } // Generate a joomla password format for the user so we can log them in. $password = JUserHelper::genRandomPassword(); $userData = array(); $userData['password'] = $password; $userData['password2'] = $password; $my->bind($userData); // User object must be saved again so the password change get's reflected. $my->save(); $mainframe->login(array('username' => $my->username, 'password' => $password)); if ($config->get('fbloginimportprofile')) { $facebook->mapProfile($userInfo, $my->id); } $tmpl = new CTemplate(); $tmpl->set('my', $my); $tmpl->set('userInfo', $userInfo); $content = $tmpl->fetch('facebook.existinguser'); $buttons = '<input type="button" class="button" onclick="joms.connect.importData();" value="' . JText::_('CC CONTINUE BUTTON') . '"/>'; // Update page token since the userid is changed now. $token = JUtility::getToken(); $response->addScriptCall('jax_token_var="' . $token . '";'); // Add invite button /** HTGMOD **/ if (JFactory::getSession()->get('device', '') == 'ios') { // wtf hax $response->addScriptCall('cWindowResize2', 300, 190, 'joms.jQuery("#cWindowContent").removeClass("resizing");'); } else { $response->addScriptCall('cWindowResize', 190); } /** END HTGMOD **/ $response->addAssign('cWindowContent', 'innerHTML', $content); $response->addScriptCall('joms.jQuery("#cwin_logo").html("' . $config->get('sitename') . '");'); $response->addScriptCall('cWindowActions', $buttons); $response->sendResponse(); } }