Example #1
0
 public static function create_proceed()
 {
     jimport('joomla.application.application');
     jimport('joomla.user.helper');
     jimport('joomla.utilities.utility');
     JPluginHelper::importPlugin('user');
     jimport('joomla.environment.request');
     JRequest::checkToken() or die('Invalid Token');
     //JSession::checkToken() or die( 'Invalid Token' );
     $session = JFactory::getSession();
     $db = JFactory::getDBO();
     $user = clone JFactory::getUser();
     $usersConfig = JComponentHelper::getParams('com_users');
     $session_me = $session->get('user_details', '');
     $myparams = JComponentHelper::getParams('com_fbconnct');
     $mainframe = JFactory::getApplication();
     $redirAfterReg = $myparams->get('redirect-after-reg');
     $postToFB = $myparams->get('post-to-facebook');
     $UserFBmsg = $myparams->get('facebook-message');
     if (!$user->get('guest')) {
         die($user->name . JText::_('COM_FBCONNCT_ALREADY_LOGGED_IN'));
     }
     $uid = $session_me['id'];
     $username = JRequest::getVar('username', '');
     $username = fbconnctController::clean_username($username);
     $createUser_url = JRoute::_('index.php?task=create&option=com_fbconnct&format=raw');
     $user_allow_post = JRequest::getVar('fbpost', '');
     if (strlen($username) < 5) {
         $fb_error = array('<div class="error">' . JText::_('COM_FBCONNCT_USERNAMETOOSHORT') . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     if (fbconnctController::count_jusername($username) > 0) {
         $fb_error = array('<div class="error">' . JText::_('COM_FBCONNCT_USERNAMEINUSE') . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     //proceed to creating user
     $session_me = $session->get('user_details', '');
     $pathway = $mainframe->getPathway();
     $newUsertype = $usersConfig->get('new_usertype', 2);
     if (!$newUsertype) {
         $newUsertype = 'Registered';
     }
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $fullname = $session_me['name'];
     $email = $session_me['email'];
     $randomepass = JUserHelper::genRandomPassword(5);
     $intdatetime = time();
     //email data
     $emailData = array();
     $emailData['name'] = $fullname;
     $emailData['username'] = $username;
     $emailData['email'] = $email;
     $emailData['temp_pass'] = $randomepass;
     $emailData['fbid'] = $uid;
     // binding process
     $userData = array();
     $userData['name'] = $fullname;
     $userData['username'] = $username;
     $userData['email'] = $email;
     $userData['password'] = $randomepass;
     $userData['password2'] = $randomepass;
     $userData['sendEmail'] = 0;
     if (!$user->bind($userData, 'usertype')) {
         $fb_error = array('<div class="error">' . $user->getError() . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     $user->set('groups', array($newUsertype));
     $user->set('id', 0);
     $date = JFactory::getDate();
     //j3 change
     $user->set('registerDate', $date->toSql());
     //j3 change
     if ($user->save()) {
         $jomuserid = $user->get('id');
         if (fbconnctController::count_fb_user($uid) >= 1) {
             $fbinsertquary = "UPDATE #__facebook_joomla_connect SET joomla_userid={$jomuserid},joined_date={$intdatetime} WHERE facebook_userid={$uid}";
         } else {
             $fbinsertquary = "INSERT INTO #__facebook_joomla_connect(joomla_userid,facebook_userid,joined_date,linked) VALUES ({$jomuserid},{$uid},{$intdatetime},1)";
         }
         $db->setQuery($fbinsertquary);
         $result = $db->query();
         if ($result) {
             $options = array();
             $options['action'] = 'core.login.site';
             $response = new stdClass();
             $response->username = $username;
             $response->password = $randomepass;
             $result = $mainframe->triggerEvent('onUserLogin', array((array) $response, $options));
             fbconnctController::emailUsers($emailData);
             fbconnctController::displayMessage(JText::_('COM_FBCONNCT_YOUR_MSG'), JText::_('COM_FBCONNCT_REGSUCCESS'), $redirAfterReg);
         } else {
             fbconnctController::emailUsers($emailData);
             fbconnctController::displayMessage(JText::_('COM_FBCONNCT_YOUR_MSG'), JText::_('COM_FBCONNCT_REGSUCCESS'), $redirAfterReg);
         }
         if ($postToFB && $user_allow_post) {
             fbconnctController::post_to_facebook($UserFBmsg, $emailData);
         }
     }
 }
Example #2
0
 public static function create_proceed()
 {
     jimport('joomla.application.application');
     jimport('joomla.user.helper');
     jimport('joomla.utilities.utility');
     JPluginHelper::importPlugin('user');
     jimport('joomla.environment.request');
     JRequest::checkToken() or die('Invalid Token');
     //JSession::checkToken() or die( 'Invalid Token' );
     $session = JFactory::getSession();
     $db = JFactory::getDBO();
     $user = clone JFactory::getUser();
     $usersConfig = JComponentHelper::getParams('com_cvnusers');
     $session_me = $session->get('user_details', '');
     $myparams = JComponentHelper::getParams('com_fbconnct');
     if (fbconnctController::isJ16()) {
         $mainframe = JFactory::getApplication();
         $redirAfterReg = $myparams->getValue('data.params.redirect-after-reg');
     } else {
         global $mainframe;
         $redirAfterReg = $myparams->get('redirect-after-reg');
     }
     if (!$user->get('guest')) {
         die($user->name . ' already logged in !');
     }
     $uid = $session_me['id'];
     $username = JRequest::getVar('username', '');
     $username = fbconnctController::clean_username($username);
     $createUser_url = JRoute::_('index.php?task=create&option=com_fbconnct&format=raw');
     //code by khanglq
     //$logtest =array();
     //jimport('joomla.log.log');
     //JLog::addLogger(array());
     //JLog::add(JText::_('$username = '******'<div class="error">' . JText::_('COM_FBCONNCT_USERNAMETOOSHORT') . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     if (fbconnctController::count_jusername($username) > 0) {
         $fb_error = array('<div class="error">' . JText::_('COM_FBCONNCT_USERNAMEINUSE') . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     //proceed to creating user
     $session_me = $session->get('user_details', '');
     $pathway = $mainframe->getPathway();
     $newUsertype = $usersConfig->get('new_usertype', 2);
     if (!fbconnctController::isJ16()) {
         if (!$newUsertype) {
             $newUsertype = 'Registered';
         }
     }
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $fullname = $session_me['name'];
     $email = $session_me['email'];
     $randomepass = JUserHelper::genRandomPassword(5);
     $intdatetime = time();
     //email data
     $emailData = array();
     $emailData['name'] = $fullname;
     $emailData['username'] = $username;
     $emailData['email'] = $email;
     $emailData['temp_pass'] = $randomepass;
     $emailData['fbid'] = $uid;
     // binding process
     $userData = array();
     $userData['name'] = $fullname;
     $userData['username'] = $username;
     $userData['email'] = $email;
     $userData['password'] = $randomepass;
     $userData['password2'] = $randomepass;
     $userData['sendEmail'] = 0;
     if (!$user->bind($userData, 'usertype')) {
         $fb_error = array('<div class="error">' . $user->getError() . '</div>');
         $session->set('fb_custom_error', $fb_error);
         $mainframe->redirect($createUser_url);
         exit;
     }
     if (fbconnctController::isJ16()) {
         $user->set('groups', array($newUsertype));
     } else {
         $user->set('usertype', $newUsertype);
         $user->set('gid', '18');
     }
     $user->set('id', 0);
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     if ($user->save()) {
         //Save additional data for player (user of chessvn)
         // Trong đây là add thêm các cột userid lấy từ bảng user, coin là tạo = 10000000;
         JLog::add(JText::_('khanglq:---facebook register -- begin go here to Save additional data for player '), JLog::INFO);
         global $newUserCoin, $defaultAvatar, $chessTypeChess, $ratingTypeStandard, $initELO;
         // Phan tao folder va copy file
         $registerDate = JFactory::getDate();
         $mediaplayer = '/mediaplayer/' . $registerDate->format('Y/Ym/Ymd/') . $user->id . '_' . $user->username;
         $path = JPATH_ROOT . '/media/media_chessvn' . $mediaplayer;
         if (JFolder::create($path)) {
             if (JFolder::create($path . '/images')) {
                 //tạo thư mục images
                 JLog::add(JText::_('khanglq111:--- Create folders sucess'), JLog::INFO);
                 $src = JPATH_ROOT . '/media/media_chessvn/images/no-avatar.jpg';
                 $dest = $path . '/images/no-avatar.jpg';
                 if (JFile::copy($src, $dest, null, true)) {
                     $defaultAvatar = '/images/no-avatar.jpg';
                     JLog::add(JText::_('khanglq1421111:--- Copy file ok'), JLog::INFO);
                 } else {
                     JLog::add(JText::_('khanglq1421111:--- Copy file failed'), JLog::INFO);
                 }
             }
         } else {
             JLog::add(JText::_('khanglq1111421:--- Create folder failed'), JLog::INFO);
         }
         $query = $db->getQuery(true);
         $columns = array('userid', 'coin', 'avatar', 'mediaplayer');
         $values = array($user->id, $newUserCoin, $db->quote($defaultAvatar), $db->quote($mediaplayer));
         $query->insert($db->quoteName('#__player'))->columns($db->quoteName($columns))->values(implode(',', $values));
         $db->setQuery($query);
         $db->execute();
         // Save additional data for rating (user for chessvn)
         $playerId = $db->insertid();
         $query = $db->getQuery(true);
         $columns = array('playerid', 'chesstype', 'ratingtype', 'ratingpoint');
         $values = array($playerId, $chessTypeChess, $db->quote($ratingTypeStandard), $initELO);
         $query->insert($db->quoteName('#__rating'))->columns($db->quoteName($columns))->values(implode(',', $values));
         $db->setQuery($query);
         $db->execute();
         JLog::add(JText::_('khanglq1111:--- Additional data saved. $newUserCoin = ' . $newUserCoin), JLog::INFO);
         //================================================
         $jomuserid = $user->get('id');
         if (fbconnctController::count_fb_user($uid) >= 1) {
             $fbinsertquery = "UPDATE #__facebook_joomla_connect SET joomla_userid={$jomuserid},joined_date={$intdatetime} WHERE facebook_userid={$uid}";
         } else {
             $fbinsertquery = "INSERT INTO #__facebook_joomla_connect(joomla_userid,facebook_userid,joined_date,linked) VALUES ({$jomuserid},{$uid},{$intdatetime},1)";
         }
         $db->setQuery($fbinsertquery);
         $result = $db->query();
         //
         if ($result) {
             $options = array();
             $options['action'] = 'core.login.site';
             $response = new stdClass();
             $response->username = $username;
             if (fbconnctController::isJ16()) {
                 $result = $mainframe->triggerEvent('onUserLogin', array((array) $response, $options));
             } else {
                 $result = $mainframe->triggerEvent('onLoginUser', array((array) $response, $options));
             }
             fbconnctController::emailUsers($emailData);
             fbconnctController::displayMessage(JText::_('COM_FBCONNCT_YOUR_MSG'), JText::_('COM_FBCONNCT_REGSUCCESS'), $redirAfterReg);
         } else {
             fbconnctController::emailUsers($emailData);
             fbconnctController::displayMessage(JText::_('COM_FBCONNCT_YOUR_MSG'), JText::_('COM_FBCONNCT_REGSUCCESS'), $redirAfterReg);
         }
     }
 }