How to redirect to a specific page/url after login

This sub-forum is for discussing all topics related to AppGini Helper JavaScript Library, provided by bizzworxx as a third-party AppGini plugin.
Post Reply
User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

How to redirect to a specific page/url after login

Post by jsetzer » 2020-07-03 09:07

Hi,

whenever you share a link (by email, QRCode, WhatsApp, ...) with another user of your AppGini-application, ...

kGElLgmNyp.png
kGElLgmNyp.png (28.62 KiB) Viewed 8426 times

...after they have logged in, they will be redirected to the homepage...

chrome_NaLKK8MMlr.png
chrome_NaLKK8MMlr.png (20.99 KiB) Viewed 8426 times

...but not to the shared page.

chrome_q5QkNIXGq9.png
chrome_q5QkNIXGq9.png (18.25 KiB) Viewed 8426 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>
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to redirect to a specific page/url after login

Post by D Oliveira » 2020-07-03 09:57

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 =)

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by jsetzer » 2020-07-03 19:41

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
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: How to redirect to a specific page/url after login

Post by D Oliveira » 2020-07-03 20:26

you're absolutely right, I exchanged my server keys with localhost's lol, thanks!!

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by jsetzer » 2020-07-03 20:35

Great, thank you for the feedback!
Jan
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by onoehring » 2020-07-18 07:29

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by jsetzer » 2020-07-18 09:33

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by jsetzer » 2020-12-18 07:43

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jhamblett
Posts: 1
Joined: 2020-12-22 17:34
Location: United Kingdom
Contact:

Re: How to redirect to a specific page/url after login

Post by jhamblett » 2020-12-22 21:52

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.
Jacob Hamblett
Director & Founder @ 21st Webb LTD

T: +44 (0) 3333 661 289
E: [email protected]
W: https://21stwebb.co.uk

sacgtdev
Veteran Member
Posts: 75
Joined: 2020-06-10 11:14

Re: How to redirect to a specific page/url after login

Post by sacgtdev » 2020-12-23 14:14

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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to redirect to a specific page/url after login

Post by jsetzer » 2021-01-08 12:42

Where does the redirect url come from?
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply