Hi,
In my project, certain steps require that the user is logged in to be able to continue. It is then first redirected to the connection page (if it is not) before being able to continue. Is it possible that he is redirected to the page where he was before he was forced to log in (to avoid him repeating all the ones he has already done previously)?
Thanks
A little confused by the question to be honest, but basically.
If using database type login authentication in your app with security providers and page restricts then your user would first start off at a login page which would verify their credentials and then you would redirect them to your secure page using the Wappler built in security.identity normally.
If the user is not logged in and goes to your secure URL manually then their security.identity should interact with the page security added and redirect them back to your login page where they can enter their credentials so the security provider can give them the security.identity allowing them to see your page.
If you are talking about OAuth API security via google or facebook then it all works quite differently for certain steps in the process.
Sorry for my bad english, I am french speaking.
Letâs just say that to validate his order, the user must be logged in (or create an account). How to redirect him to the validation page of his order after he has connected. But this example is valid for any page (no restriction of access to these pages)
Ok I think I get it now, so like an online shop where the user can add items to their cart without registering or logging in first. Then if they decide to verify the order, they need to create an account or login and for their same items placed in their shopping cart to be added to their profile.
Best option if some parts of your process require login and other parts donât is to make them create an account or login to their account first, if that is not possible or desirable.
Second option is to use a unique session identifier and place all their cart items under their session, when they want to check out and need to register or login then update their session information stored in the temporary table under their user identifier that your shopping cart system uses.
@ben would possibly be better suited to answer though as he has done shopping cart type stuff with Wappler.
The example of e commerce was just to illustrate the case. I want to set up the functionality on all pages where the user will decide to connect (or would be forced to do so). Is it possible to put the current or previous url in a variable that could be reused to redirect to the previous page?
Would I be right that youâre looking for this solution?
Visitor is on a page in your site. They go to another page which is restricted (requires to be logged in) but, as they are not logged in they are bounced to the login page. But, after then entering their login details, you want them to redirect back to the page they attempted to view before the logging in?
So, the pages need to store the current URL somewhere, then bounce to the login page, then redirect to that stored URL after the logging in is successful.
Is that correct?
Yes, I need to store the current url in a variable and how to reuse it after login so I can be
redirect to this previous page
This assumes that we know the page to which we want to redirect the user. In my case, this can be any page âŚ
I think this can be to any page - whatever page the user intended to go to before having to log in. (But I may have misunderstood the question.)
If I understood correctly, in this example we know in advance to which page the user should be redirected. In my case, we donât know
To quote from one of the comments on the thread:
⌠you need them to be redirected to the page they previously requested which could be one of many different pages?
I thought this was the issue you wanted to find a solution to.
Absolutely. When is the url of the previous page identified and retrieved for reuse?
In this example, I understand that he wants to redirect to the page âweb-user.phpâ, in my case, I do not know in advance to which page he should be redirected hence the need to retrieve his URL.
@Djibril All you need to do is set this up in the Security Provider window. See here.
So in your case, on the âweb-user.phpâ page you will have security provider with If User Not Logged In, Go To field set as âlogin.php?return=web-user.phpâ (login.php being your login page).
Then if a user hits your web-user.php and is not signed in, they will be re-directed to the login page and then finally back to the web-user page once signed in. Hope that makes sense.
This should really be placed in the How To section
Hi TomD, thanks a lot. This is a solution indeed.
Hi,
Here is a solution I founded to redirect to the previous page (like the back button of a browser).
Sorry in advance for my mistakes, I am not a developer, just an enthusiast who learns. I am waiting for your comments!
Step 1
I created 2 pages containing only the âmainâ, ârowâ and âcolâ tags. I named them âfirst_page.phpâ and âsecond_page.phpâ.
Step 2
Insert in the first page, the custom php script which allows to recover the URL of the current page.
The script is bellow
<?php $uri = $_SERVER['REQUEST_URI']; $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $query = $_SERVER['QUERY_STRING']; ?>Step 3
Insert the âBrowserâ component from the âApp structureâ panel. Select âAppâ in the âApp Structureâ pane, click on â+â. In the new window, select âComponentâ, then click on âBrowserâ
Step 4
Insert the âSession Storage Managerâ component from the âApp structureâ panel.
Select âAppâ, then click on â+â. In the new window, select âState Managementâ, then click on âSession Storage Managerâ.
Step 5
With âSession Storage Managerâ selected in âApp Structureâ, click on âDefine Session Storage Itemsâ
Step 6
In the new window, right click on âSession Stoarageâ and select âAdd variableâ
Step 7
Rename the variable âpreviouspageâ and click on âSelectâ
Step 8
We will use a form with an âimputâ tag to retrieve the URL of the current page
Select the âcolumnâ tag and insert a âformâ tag inside from the âApp structureâ panel
Step 9
The âformâ tag still selected, set method to âpostâ
Step 10
The âformâ tag still selected, insert in âactionâ the path of the file to which we should be redirected after submission of the form
Step 11
Insert an âimputâ tag inside. Select the form, click on â+â in âApp Structureâ. In the new window, select âinsert childâ, then âformâ, then select âText inputâ.
Step 12
Set âimputâ tag type to âhiddenâ
Step 13
Insert the following custom php script for the static value of the âimputâ tag : <?php echo $url; ?>
Step 14
Insert a button after the âimputâ tag
Step 15
For the functionality of retrieving the URL of the current page, letâs select the âformâ tag and define a dynamic event
Step 16
In the new window, select âformâ and then âsubmitâ event
Step 17
Click on the thunder in front of the âsubmitâ event to define the properties
Step 18
In the new window, select âsetâ under the âSession Storage Managerâ pane, then â+â, finally the session variable that we have defined before
Step 19
Then click on the thunder in front of âvalueâ
Step 20
In the new window, select âvalueâ under the âformâ tag and click on âselectâ
Step 21
Back on the previous window, define the redirection property.
Select âGo Toâ in the âBrowserâ pane, then click on â+â, select the new action that has just been added and finally define the path of the desired page in the âGo To Propertiesâ section.
Thatâs it. The first page is ready. Do not forget to save it before going to the second page.
Step 22
On the second page, we will add the âBrowserâ component by selecting âAppâ in the âApp structureâ pane, click on â+â, select âcomponentâ, then âBrowserâ.
Step 23
While keeping âAppâ selected in the âApp structureâ pane, letâs add âSession Storage Managerâ to the page to retrieve the URL of the previous page.
Click on â+â, and in the new window, select âState Managementâ and click on âSession Storage Managerâ
Step 24
Make sure that the ID of âSession Storage Managerâ is identical to that of the previous page
Step 25
Letâs add the button which will be used to redirect to the previous page. Select the âinputâ tag, in the âApp Structureâ pane, click on â+â, then âinsert childâ.
In the new window, click on âButtonâ
Step 26
Letâs define the redirect functionality. Select âButtonâ and â+â in front of âDynamic eventâ under the âPropertiesâ tab
Step 27
In the new window, select âMouseâ, then âClickâ
Step 28
Click on the thunder placed in front of the new action which is under the section âDynamic eventâ
Step 29
In the new window, select âGo Toâ under the âBrowserâ tab, then click on â+â, then select the new action that has just been created and finally on the lightning in the âGo To propertiesâ section
Step 30
In the new window, click on the âpreviouspageâ variable under the âSession Storage Managerâ tab then on âselectâ
Step31
Back to the previous window, click on âselectâ, save your page and thatâs it.