Skip to content

Commit

Permalink
Merge pull request #5551 from hoang-tran-redweb/LAC-98
Browse files Browse the repository at this point in the history
LAC-98: Update code plugin login facebook and google.
  • Loading branch information
Lu Nguyen Nhat authored Jul 4, 2022
2 parents 386bbfe + b11fe41 commit c6a8f2a
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 4 deletions.
19 changes: 18 additions & 1 deletion libraries/redshop/src/Helper/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ class Login
public static function loginJoomlaRedShop($data) {
$app = \JFactory::getApplication();
$jUser = \JUserHelper::getUserId($data['email']);
$pluginName = substr($app->input->get('plugin'), 0, -13);
if (isset($pluginName) && $pluginName == 'google') {
$pluginName = 'google';
} else {
$pluginName = 'facebook';
}
$plugin = \JPluginHelper::getPlugin('redshop_login', $pluginName);
$params = json_decode($plugin->params);
$returnId = $params->redirectlogin;
$menu = \JFactory::getApplication()->getMenu();
$item = $menu->getItem($returnId);

if ($jUser > 0) {
$jUser = \JFactory::getUser($jUser);
Expand All @@ -46,7 +57,13 @@ public static function loginJoomlaRedShop($data) {
$redUser = \RedshopHelperUser::storeRedshopUser($data, $jUser->id);
}

$app->redirect(\JUri::root());
if ($item) {
$link = $item->link . '&Itemid=' . $returnId;
} else {
$link = \JUri::root();
}

$app->redirect($link);
}

/**
Expand Down
48 changes: 48 additions & 0 deletions plugins/redshop_login/facebook/element/callbackurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* SLogin
*
* @version 2.9.1
* @author SmokerMan, Arkadiy, Joomline
* @copyright © 2012-2020. All rights reserved.
* @license GNU/GPL v.3 or later.
*/

// защита от прямого доступа
defined('_JEXEC') or die('@-_-@');

jimport('joomla.form.formfield');

class JFormFieldCallbackUrl extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'CallbackUrl';

/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$task = !empty($this->element['value']) ? '?index.php?option=com_ajax&group=redshop_login&plugin=fbLoginCallBack&format=raw' : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';

$CallbackUrl = JURI::root().$task;

if(substr($CallbackUrl, -1, 1) == '/'){
$CallbackUrl = substr($CallbackUrl, 0, -1);
}

$html = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'.$CallbackUrl.'" size="70%" '. $class . $readonly .' />';

return $html;
}
}
4 changes: 2 additions & 2 deletions plugins/redshop_login/facebook/facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function onThirdPartyLogin()
$permissions = ['email']; // Optional permissions

$linkLogin = $helper->getLoginUrl(
\Redshop\IO\Route::_(
JRoute::_(
\JUri::root() . 'index.php?option=com_ajax&group=redshop_login&plugin=fbLoginCallBack&format=raw'
),
$permissions
Expand All @@ -58,7 +58,7 @@ public function onAjaxFbLoginCallBack()
$helper = $fb->getRedirectLoginHelper();

try {
$accessToken = $helper->getAccessToken();
$accessToken = $helper->getAccessToken('https://dev.lacaph.com.web1.redhost.vn/index.php?option=com_ajax&group=redshop_login&plugin=fbLoginCallBack&format=raw');
} catch (\Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
$app->enqueueMessage('Graph returned an error: ' . $e->getMessage());
Expand Down
16 changes: 16 additions & 0 deletions plugins/redshop_login/facebook/facebook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<filename plugin="facebook">facebook.php</filename>
<filename plugin="facebook">index.html</filename>
<folder>library</folder>
<folder>element</folder>
</files>
<config>
<fields name="params">
Expand All @@ -32,6 +33,21 @@
type="text"
label="PLG_REDSHOP_LOGIN_FACEBOOK_APP_SECRET"
/>
<field addfieldpath="plugins/redshop_login/facebook/element"
name="callback_url"
type="callbackurl"
description="Callback URL"
filter="unset"
value="google"
readonly="true"
class="readonly"
label="PLG_REDSHOP_LOGIN_GOOGLE_CALLBACK_URL"
/>
<field addfieldpath="plugins/redshop_login/facebook/element"
name="redirectlogin"
type="menuitem"
label="PLG_REDSHOP_LOGIN_GOOGLE_LOGIN_REDIRECT"
/>
</fieldset>
</fields>
</config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ PLG_REDSHOP_LOGIN_FACEBOOK="redSHOP Login - Facebook"
PLG_REDSHOP_LOGIN_FACEBOOK_DESC="redSHOP Login - Facebook"
PLG_REDSHOP_LOGIN_FACEBOOK_APP_ID="App Id"
PLG_REDSHOP_LOGIN_FACEBOOK_APP_SECRET="App secret"
PLG_REDSHOP_LOGIN_GOOGLE_CALLBACK_URL="Callback url"
PLG_REDSHOP_LOGIN_GOOGLE_LOGIN_REDIRECT="Login redirect"
48 changes: 48 additions & 0 deletions plugins/redshop_login/google/element/callbackurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* SLogin
*
* @version 2.9.1
* @author SmokerMan, Arkadiy, Joomline
* @copyright © 2012-2020. All rights reserved.
* @license GNU/GPL v.3 or later.
*/

// защита от прямого доступа
defined('_JEXEC') or die('@-_-@');

jimport('joomla.form.formfield');

class JFormFieldCallbackUrl extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'CallbackUrl';

/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$task = !empty($this->element['value']) ? '?index.php?option=com_ajax&group=redshop_login&plugin=googleLoginCallBack&format=raw' : '';
$readonly = ((string) $this->element['readonly'] == 'true') ? ' readonly="readonly"' : '';
$class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';

$CallbackUrl = JURI::root().$task;

if(substr($CallbackUrl, -1, 1) == '/'){
$CallbackUrl = substr($CallbackUrl, 0, -1);
}

$html = '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'.$CallbackUrl.'" size="70%" '. $class . $readonly .' />';

return $html;
}
}
2 changes: 1 addition & 1 deletion plugins/redshop_login/google/google.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getGoogleObject()
{
$client = new Google_Client();

$redirectUri = \Redshop\IO\Route::_(
$redirectUri = JRoute::_(
\JUri::root() . 'index.php?option=com_ajax&group=redshop_login&plugin=googleLoginCallBack&format=raw'
); // URL này được Google chuyển hướng, khi người dùng đồng ý

Expand Down
16 changes: 16 additions & 0 deletions plugins/redshop_login/google/google.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<filename plugin="google">google.php</filename>
<filename plugin="google">index.html</filename>
<folder>library</folder>
<folder>element</folder>
</files>
<config>
<fields name="params">
Expand All @@ -32,6 +33,21 @@
type="text"
label="PLG_REDSHOP_LOGIN_GOOGLE_SECRET"
/>
<field addfieldpath="plugins/redshop_login/google/element"
name="callback_url"
type="callbackurl"
description="Callback URL"
filter="unset"
value="google"
readonly="true"
class="readonly"
label="PLG_REDSHOP_LOGIN_GOOGLE_CALLBACK_URL"
/>
<field addfieldpath="plugins/redshop_login/google/element"
name="redirectlogin"
type="menuitem"
label="PLG_REDSHOP_LOGIN_GOOGLE_LOGIN_REDIRECT"
/>
</fieldset>
</fields>
</config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ PLG_REDSHOP_LOGIN_GOOGLE="redSHOP Login - Google"
PLG_REDSHOP_LOGIN_GOOGLE_DESC="redSHOP Login - Google"
PLG_REDSHOP_LOGIN_GOOGLE_CLIENT_ID="Client id"
PLG_REDSHOP_LOGIN_GOOGLE_SECRET="Secret"
PLG_REDSHOP_LOGIN_GOOGLE_CALLBACK_URL="Callback url"
PLG_REDSHOP_LOGIN_GOOGLE_LOGIN_REDIRECT="Login redirect"

0 comments on commit c6a8f2a

Please sign in to comment.