If website is offline, then after logging in, return to the previous page#22480
If website is offline, then after logging in, return to the previous page#22480csthomas wants to merge 2 commits intojoomla:stagingfrom
Conversation
|
I have tested this item ✅ successfully on 7a7fa48 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22480. |
|
Although this works, I see no real use for it. The case is so much to the edge that one needs binoculars to even consider it. (That was a joke: 😺 ) |
|
@csthomas thanks for this. It will save me a lot of time. |
|
This PR does not do any important thing but correctly describe (in code) how to back to previous page after logged in. This PR is a part of #22229, which I wanted to do separately. I would like to standardize the way of generating the action link of the form:
|
|
@vc-development @viocassel Test patch, go to https://issues.joomla.org/tracker/joomla-cms/22480 and click "Test this" and fill in a form. |
|
I have tested this item ✅ successfully on 7a7fa48 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22480. |
|
@csthomas done 👍 |
|
I have tested this item ✅ successfully on 7a7fa48 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/22480. |
|
Please do not use multiple github accounts to report that you have tested something more than once |
|
@brianteeman the second account is not mine, but this is my friend's account 😉 |
| <input type="hidden" name="option" value="com_users" /> | ||
| <input type="hidden" name="task" value="user.login" /> | ||
| <input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" /> | ||
| <?php $uri = new Uri('index.php'); ?> |
There was a problem hiding this comment.
I think you can do this in a single line with:
<input type="hidden" name="return" value="<?php echo base64_encode(Uri::getInstance()->tostring()); ?>" />| <input type="hidden" name="option" value="com_users" /> | ||
| <input type="hidden" name="task" value="user.login" /> | ||
| <input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" /> | ||
| <?php $uri = new Uri('index.php'); ?> |
|
@phproberto echo Uri::getInstance()->tostring(); // this is get from $_SERVERand $uri = new Uri('index.php');
$uri->setQuery($app->getRouter()->getVars());
echo $uri->tostring();When SEF is ON the first one can display e.g. Following https://docs.joomla.org/How_do_you_redirect_users_after_a_successful_login%3F#Overriding the |
|
I've just tested it with SEF ON with an URL like // Prints http://localhost/joomla-cms/article-category-list?start=10
var_dump(Uri::getInstance()->toString());
// True
var_dump(Uri::isInternal(Uri::getInstance()->toString()));
$uri = new Uri('index.php');
$uri->setQuery($app->getRouter()->getVars());
// Prints index.php?Itemid=260&option=com_content
var_dump($uri->toString());Note that This code is already used and tested in in mod_login: So I'd definitely use I promise to test your PR if you change it 😄 |
|
I have fixed issue with Why I force it? $uri = new Uri('index.php');
$uri->setQuery($app->getRouter()->getVars());For offline page If you start using association on multilingual website then you will see the difference for offline page. The form is generated as For e.g. create 2 pages for English and German and associate them (/en/english-blog, /de/german-blog). As user frontend language is German and you go to I know that for offline pages this is not important but I we will use this at diff --git a/libraries/src/Application/SiteApplication.php b/libraries/src/Application/SiteApplication.php
index f6dbe5408a..39c25c8acf 100644
--- a/libraries/src/Application/SiteApplication.php
+++ b/libraries/src/Application/SiteApplication.php
@@ -86,8 +86,11 @@ final class SiteApplication extends CMSApplication
{
if ($user->get('id') == 0)
{
+ $uri = new \JUri('index.php');
+ $uri->setQuery($this->getRouter()->getVars());
+
// Set the data
- $this->setUserState('users.login.form.data', array('return' => \JUri::getInstance()->toString()));
+ $this->setUserState('users.login.form.data', array('return' => $uri->toString()));
$url = \JRoute::_('index.php?option=com_users&view=login', false);
then association start working when you go to restricted area (registered only) e.g. |
False. My solution works as expected with mod_login so it's not about using Uri::getInstance() or not. My setup:
I also tested the previous setup with links that are not the home page. It also works redirecting. So then if my solution works with mod_login (and it has been used & tested for years) why does it fail in your offline? Because the changes you did. Use previous form action: <form action="<?php echo JRoute::_('index.php', true); ?>" method="post" id="form-login">And add back the $_POST data that you removed: <input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="user.login" />You will notice that it works. So changing one line of code everything would work as you wanted. From: <input type="hidden" name="return" value="<?php echo base64_encode(JUri::base()); ?>" />to: <input type="hidden" name="return" value="<?php echo base64_encode(JUri::getInstance()->toString()); ?>" />That's all! Summary:
About the changes you propose for:
I cannot make it working with your code because return is hardcoded in offline template and not reading from the login data in session. It requires a more complicated solution. Anyway I'm abandoning here. I've invested enough time testing things. You already decided to follow your way. Good luck! |
I knew from the beginning that it works if you put it back <form action="<?php echo JRoute::_('index.php', true); ?>" method="post" id="form-login">but it looks ugly, the action URL is an URL of the current page and you have to override The form action URL should point to the login form ( I will prepare a separate PR about the changes I proposed in |
|
I created a new PR to fix issue for restricted menu item with association enabled on multilingual website. #22677 |
|
The PR died because a problem with B/C. See #22677. |
Summary of Changes
If website is offline, then after logging in, return to the previous page
Testing Instructions
As a guest go to any subpage (article) of your website.
On backend in another tab set website offline.
Refresh page on front end and log in as Super User.
Expected result
After log in you stay on the same page.
Actual result
After login you are redirected to the home page.
Documentation Changes Required
No