How to: Redirect to requested page after login
03/07/2020

Sometimes, in our AppGini applications we'd like to share data with co-workers or other users by sending a link via email, for example. Unfortunately, this does not work as expected, by default.

I am going to show a very simple, solution, based on our AppGini Helper Javascript Library.

AppGini default behaviour

By default, if we are not logged in already, AppGini redirects us to the login-page first, then to the homepage (index.php) after login.

graph LR S((Start)) ==> A{Authorized<br>?} A -. yes .-> P([Requested Page]) A == no ==> L([Login]) L ==> A2{Authorized<br>?} A2 -- no --> L A2 == yes ==> H([Homepage]) H ==>E((End)) P -.-> E classDef red fill:#eee,stroke:#f00,color:#f00,stroke-width:1px; class H red; classDef orange fill:#eee,stroke:#aaa,color:#aaa,stroke-width:2px,stroke-dasharray:5,2 class P orange; classDef standard fill:#eee,stroke:#333,color:#000,stroke-width:1px; class S,A,A2,L,E standard;

This means the user will not see the requested page unless he/she clicks the link again (or copies the url into the browser's address bar).

AppGini Default

But this is not what we want at all. We'd like to redirect the user to the requested page after login, not to the homepage.


Expectation

What we want is, when the recipient clicks the link, his/her browser should open up and show the shared page after login.

graph LR S((Start)) ==> A{Authorized<br>?} A == no ==> L([Login]) L ==> A2{Authorized<br>?} A2 -- no --> L A2 == yes ==> P A -. yes .-> P([Requested Page]) P --> E((End)) classDef green fill:#fafafa,stroke:#0a0,color:#0a0,stroke-width:2px; class P green; classDef standard fill:#eee,stroke:#333,color:#000,stroke-width:1px; class S,A,A2,L,E standard;

Solution

Please note that this is BETA for testing purposes. Please provide feedback if this works for you or not.

We have done all the hard work for you and provide a simple solution:

Code

<!-- file: hooks/header-extras.php -->
<script>
  var common = new AppGiniCommon();
  common.autoRedirect();
</script>

That's all you have to do. Just call the autoRedirect() function on the AppGiniCommon object. Our library will do the rest.

Result

Wanna see it in action?


Pro-Tipp:

This integrates nicely with QR-Codes

AppGini Helper PACK: New Version 1.2
30/06/2020

New version with custom blacklist option and another option for copying required files without compressing.

Compress vs. Copy

When "Compress" is checked, this is the already known zip-compression: Necessary files will be compressed and stored as zip-file in a subdirectory of .release.

If you unckeck "compress", the required files will just be copied "as is" into a new subdirectory of .release. This option can be helpful for FTP upload of project files.

Blacklist

Now you can add custom folders and search-patterns. Folders/Files matching the blacklist will be excluded.

Version 1.2 is available for download now.

BUG: display of dropdowns/lookups in tabs
15/06/2020

There is a display bug for the add-/view- buttons next to dropdowns when applying field.dropdown().fix() on fields placed in tabs.

The reason is that select2 dropdown container returns height = 0 in certain scenarios when applying the fix.

Additionally there is an inheited css style for overflow-x which may hide the add-/view- buttons in certain sizing-scenarios.

This bug will be fixed in next version which will be released probably in July 2020. We are sorry for any inconvenience!

Refers to: