Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect after login?

in my Grails app I have a couple of simple security filters (please note it's just a prototype, not a commercial app:

securityCheckFilter(controller:'overview', invert:true) {
            before = {
                if(!session?.gaSession?.gaUser) {
                    flash.message = "You are not authorised to see this page. Please login."
                    redirect(controller:'overview',action:'login')
                    return false
                }
                return true
            }
        }

Which means that, apart from the controller 'overview' that handles the login/registration, all the other controllers require authentication. The problem is that I'd like to implement this typical flow:

(1) user tries protected url (2) redirection to login (3) successful login (4) redirection to url

In my code it works until point 3, but I'm missing 4.

Any hints?

like image 839
Mulone Avatar asked Jun 15 '10 16:06

Mulone


People also ask

How do I redirect a login page?

To redirect the user after they log out from a specific application, you must add the URL used in the returnTo parameter of the redirect URL to the Allowed Logout URLs list in the Settings tab of your Auth0 application that is associated with the CLIENT_ID parameter.

How do I redirect a WordPress site after login?

WP Login and Logout RedirectUpon installation, you'll find the new Redirect Options menu in your sidebar. Click it, and you'll see two boxes: Login Redirect URL and Logout Redirect URL. Put the URL you want in and click Save Changes, and you're done. Redirect options in the WP Login and Logout Redirect plugin.

How do I create a login page redirect in HTML?

To redirect from an HTML page, we use the META Tag. Along with this, we also use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value in the content is the number of seconds; you want the page to redirect after.


1 Answers

It's actually quite easy. Just

  • submit the target URI (from point 1 in your question) as a parameter to the login action/view
  • make sure your login form forwards this parameter to the authentication action (eg. via a hidden field)
  • in the authentication action, if the login was successful, just redirect to this URI

To get the target URI (in your filter), just remove the context path from the forward URI:

def targetURI = request.forwardURI - request.contextPath
like image 174
Daniel Rinser Avatar answered Sep 28 '22 19:09

Daniel Rinser