Skip to content

Commit

Permalink
Revert to plugin system languageflter and fix form login action link
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Narloch committed Jan 4, 2018
1 parent 05fd1d9 commit fbc245b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
3 changes: 2 additions & 1 deletion components/com_users/views/login/tmpl/default_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<?php if (($this->params->get('logindescription_show') == 1 && str_replace(' ', '', $this->params->get('login_description')) != '') || $this->params->get('login_image') != '') : ?>
</div>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" class="form-validate form-horizontal well">
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login'); ?>" method="post" class="form-validate form-horizontal well">
<fieldset>
<?php foreach ($this->form->getFieldset('credentials') as $field) : ?>
<?php if (!$field->hidden) : ?>
Expand Down Expand Up @@ -76,6 +76,7 @@
</button>
</div>
</div>
<input type="hidden" name="task" value="user.login" />
<?php $return = $this->form->getValue('return', '', $this->params->get('login_redirect_url', $this->params->get('login_redirect_menuitem'))); ?>
<input type="hidden" name="return" value="<?php echo base64_encode($return); ?>" />
<?php echo JHtml::_('form.token'); ?>
Expand Down
3 changes: 2 additions & 1 deletion modules/mod_login/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
JHtml::_('bootstrap.tooltip');

?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login', true, $params->get('usesecure')); ?>" method="post" id="login-form" class="form-inline">
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login', true, $params->get('usesecure')); ?>" method="post" id="login-form" class="form-inline">
<?php if ($params->get('pretext')) : ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
Expand Down Expand Up @@ -111,6 +111,7 @@
<?php echo JText::_('MOD_LOGIN_FORGOT_YOUR_PASSWORD'); ?></a>
</li>
</ul>
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
Expand Down
62 changes: 30 additions & 32 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,25 +616,42 @@ public function onUserLogin($user, $options = array())
$lang_code = $this->current_lang;
}

$foundAssociation = false;
// Try to get association from the current active menu item
$active = $menu->getActive();

$assoc = JLanguageAssociations::isEnabled();
$foundAssociation = false;

// If association is enabled
if ($assoc)
/**
* Looking for associations.
* If the login menu item form contains an internal URL redirection,
* this will override the automatic change to the user preferred site language.
* In that case we use the redirect as defined in the menu item.
* Otherwise we redirect, when available, to the user preferred site language.
*/
if (!$active || !$active->params['login_redirect_url'])
{
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));
if (JLanguageAssociations::isEnabled())
{
// Retrieves the Itemid from a login form.
$uri = new JUri($this->app->getUserState('users.login.form.return'));

// Get Itemid from SEF or home page
$query = $this->app->getRouter()->parse($uri);
// Get Itemid from SEF or home page
$query = $this->app->getRouter()->parse($uri);

if (!empty($query['Itemid']))
{
// The login form contains a menu item redirection. Try to get associations from that menu item.
$associations = MenusHelper::getAssociations($query['Itemid']);
}
elseif ($active)
{
$associations = MenusHelper::getAssociations($active->id);
}
}

// Check, if the login form contains a menu item redirection.
if (!empty($query['Itemid']))
{
// Try to get associations from that menu item.
$associations = MenusHelper::getAssociations($query['Itemid']);

// If any association set to the user preferred site language, redirect to that page.
if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
Expand All @@ -643,26 +660,7 @@ public function onUserLogin($user, $options = array())
$foundAssociation = true;
}
}
}

// Try to get association from the current active menu item
$active = $menu->getActive();

/**
* Looking for associations.
* If the login menu item form contains an internal URL redirection,
* This will override the automatic change to the user preferred site language.
* In that case we use the redirect as defined in the menu item.
* Otherwise we redirect, when available, to the user preferred site language.
*/
if (!$foundAssociation && $active && !$active->params['login_redirect_url'])
{
if ($assoc)
{
$associations = MenusHelper::getAssociations($active->id);
}

if (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
elseif (isset($associations[$lang_code]) && $menu->getItem($associations[$lang_code]))
{
/**
* The login form does not contain a menu item redirection.
Expand All @@ -673,7 +671,7 @@ public function onUserLogin($user, $options = array())
$this->app->setUserState('users.login.form.return', 'index.php?Itemid=' . $associationItemid);
$foundAssociation = true;
}
elseif ($active->home)
elseif ($active && $active->home)
{
// We are on a Home page, we redirect to the user preferred site language Home page.
$item = $menu->getDefault($lang_code);
Expand Down
3 changes: 2 additions & 1 deletion templates/beez3/html/mod_login/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

JHtml::_('behavior.keepalive');
?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login', true, $params->get('usesecure')); ?>" method="post" id="login-form" >
<?php if ($params->get('pretext')) : ?>
<div class="pretext">
<p><?php echo $params->get('pretext'); ?></p>
Expand Down Expand Up @@ -49,6 +49,7 @@
</p>
<?php endif; ?>
<input type="submit" name="Submit" class="button" value="<?php echo JText::_('JLOGIN') ?>" />
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHtml::_('form.token'); ?>
<ul>
Expand Down
3 changes: 2 additions & 1 deletion templates/protostar/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<?php endif; ?>
</div>
<jdoc:include type="message" />
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" id="form-login">
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login'); ?>" method="post" id="form-login">
<fieldset>
<label for="username"><?php echo JText::_('JGLOBAL_USERNAME'); ?></label>
<input name="username" id="username" type="text" title="<?php echo JText::_('JGLOBAL_USERNAME'); ?>" />
Expand All @@ -131,6 +131,7 @@

<input type="submit" name="Submit" class="btn btn-primary" value="<?php echo JText::_('JLOGIN'); ?>" />

<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
Expand Down
3 changes: 2 additions & 1 deletion templates/system/offline.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<?php echo JText::_('JOFFLINE_MESSAGE'); ?>
</p>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" id="form-login">
<form action="<?php echo JRoute::_('index.php?option=com_users&view=login'); ?>" method="post" id="form-login">
<fieldset class="input">
<p id="form-login-username">
<label for="username"><?php echo JText::_('JGLOBAL_USERNAME'); ?></label>
Expand All @@ -77,6 +77,7 @@
<p id="submit-buton">
<input type="submit" name="Submit" class="button login" value="<?php echo JText::_('JLOGIN'); ?>" />
</p>
<input type="hidden" name="task" value="user.login" />
<input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" />
<?php echo JHtml::_('form.token'); ?>
</fieldset>
Expand Down

0 comments on commit fbc245b

Please sign in to comment.