Page 1 of 1
How to redirect to a specific page/url after login
Posted: 2020-07-03 09:07
by jsetzer
Hi,
whenever you share a link (by email, QRCode, WhatsApp, ...) with another user of your AppGini-application, ...

- kGElLgmNyp.png (28.62 KiB) Viewed 35700 times
...after they have logged in, they will be redirected to the homepage...

- chrome_NaLKK8MMlr.png (20.99 KiB) Viewed 35700 times
...but
not to the shared page.

- chrome_q5QkNIXGq9.png (18.25 KiB) Viewed 35700 times

But that is exactly what I need in many scenarios.
I have written a "how-to"-article in which I explain the default behaviour and describe a very simple ("one-liner") solution using our AppGini Helper Javascript Library.
https://appgini.bizzworxx.de/appgini/ho ... ter-login/
I really hope you like it and you find it as useful as I do!
Regards,
Jan
PS: The
autoRedirect() function being used there is tested but
BETA. Please provide some feedback if this works for you or not.
PPS: tl;dr
Code: Select all
<!-- file: hooks/header-extras.php -->
<script>
var common = new AppGiniCommon();
common.autoRedirect(); // <----- magic
</script>
Re: How to redirect to a specific page/url after login
Posted: 2020-07-03 09:57
by D Oliveira
dude thats is just amazing, one of my apps have a "share recipe" button through whatsapp and every time ppl need to go through the login page to see it, my question is, how to adapt that to work with google captcha security ? thanks a lot jan, you're a gem to this community =)
Re: How to redirect to a specific page/url after login
Posted: 2020-07-03 19:41
by jsetzer
Thanks a lot for your feedback! It is particularly good for me today!
[...] how to adapt that to work with google captcha security ?
Well, the script itself does
not change the login-form nor the login-procedure at all.
So I think if you have managed to integrate your AppGini login with Google Captcha there should not be any problem caused by .autoRedirect() function, because it is just a redirect.
Regards,
Jan
Re: How to redirect to a specific page/url after login
Posted: 2020-07-03 20:26
by D Oliveira
you're absolutely right, I exchanged my server keys with localhost's lol, thanks!!
Re: How to redirect to a specific page/url after login
Posted: 2020-07-03 20:35
by jsetzer
Great, thank you for the feedback!
Jan
Re: How to redirect to a specific page/url after login
Posted: 2020-07-18 07:29
by onoehring
Hi Jan,
did you notice this post from pbötcher:
viewtopic.php?f=4&t=3744
Seems to me pretty similar.
Great post on your page.
Olaf
Re: How to redirect to a specific page/url after login
Posted: 2020-07-18 09:33
by jsetzer
Hi Olaf,
thank you for the compliment!
Code: Select all
new AppGiniCommon().autoRedirect();
Please note that the "one-liner" I have posted in this sub-forum
requires AppGini Helper Javascript Library, whilst the other solution
already works with standard AppGini generated code. I really appreciate the other contribution.
Some background info:
Due to a community member's complaint in 2019, there is
this dedicated subforum and there is an agreement between Ahmed and me, that I shall not post AppGini Helper related solutions in the general forum but only in this sub-forum, unless someone asks directly. So since this subforum exists I pay attention to it. I try to stick to our agreement as best I can. It happens from time to time that customers of mine ask questions in the general forum but I must not show a working solution based on our library. This is bad luck for those community members. And it costs them valuable time - especially when nobody else publishes a working solution in finite time. Anyway, it is important to me that I take that complaint seriously. In my opinion, the one who complained is right that basically free solutions and commercial solutions should be separated in the forum or should be highlighted as "requires commercial license". However, there are many solutions or extensions in the forum that may also require a commercial license, for example amCharts, Fullcalendar Scheduler, or Oracle Java. Other rules probably apply to these.
Re: How to redirect to a specific page/url after login
Posted: 2020-12-18 07:43
by jsetzer
Please note that the autoRedirect() function currently works when you enter the application, for example when you click on a link in an email and a new browser tab opens. It does not work if you are already on the application, for example as an anonymous user "guest" and navigate to a restricted page from there.
I plan to extend the existing function for exactly such use cases in the next release.
Re: How to redirect to a specific page/url after login
Posted: 2020-12-22 21:52
by jhamblett
Being a big fan of the Appgini Helper library produced by Jan and his team, we are thrilled to hear that the current redirect functionality will be extended to work from links within the application.
For anyone who wants to link from an unrestricted page in their Appgini application, to a restricted page elsewhere in their Appgini application, I have come up with a work around in the form of some (mainly) JavaScript code to be included in the hooks/header-extras.php file:
Code: Select all
<!-- redirect user to requested URL after logging in, if authentication was required when accessing a given URL -->
<script>
window.addEventListener("load", function() {
var requested_url = window.location.href;
var user_group = '<?php echo ($memberInfo['group']); ?>';
var access_denied = ($j(`div p:contains("Sorry! You don't have permission to access this table. Please contact the admin.")`).length > 0) ? ('true') : ('false');
var redirect_cookie_value = decodeURIComponent(!!RegExp('APPGINI_REDIRECT'+"=[^;]+").exec(document.cookie) ? RegExp('APPGINI_REDIRECT'+"=[^;]+").exec(document.cookie).toString().replace(/^[^=]+./,"") : "");
//if the page attempted to access is restricted, set cookie and redirect user...
if (user_group == 'anonymous' && access_denied == 'true') {
//set the redirect cookie to the requested url
document.cookie = "APPGINI_REDIRECT=" + window.location.href;
//redirect the user to the sign in page
window.location.replace("index.php?signIn=1");
}
//if the cookie is still set and the page is not a login or signup page...
else if (redirect_cookie_value != "" && window.location.href.indexOf("?signIn=1") == -1 && window.location.href.indexOf("membership_signup.php") == -1 && window.location.href.indexOf("membership_thankyou.php") == -1) {
//clear the redirect cookie
document.cookie = 'APPGINI_REDIRECT=; expires=Thu, 01-Jan-70 00:00:01 GMT;'
//rediretc user to the redirect cookie value
window.location.replace(redirect_cookie_value);
}
});
</script>
This is using a Cookie to store the originally requested URL, redirect the user to sign in, then attempt to access that original URL once the user has signed in / up.
Re: How to redirect to a specific page/url after login
Posted: 2020-12-23 14:14
by sacgtdev
Weird url after trying to log in. Log in fail because the 'triple slash' in the redirect url.
Not encounter this in apache web server (XAMPP) before.
First time experience this in IIS web server. Any solution for this?
Login url:
http://localhost/index.php?signIn=1
Redirect url:
http://localhost///index.php?signIn=1
Re: How to redirect to a specific page/url after login
Posted: 2021-01-08 12:42
by jsetzer
Where does the redirect url come from?