[Catalyst] HOWTO: extend the Authentication tutorial example and redirect to original URI

Chisel Wright chisel at herlpacker.co.uk
Thu Mar 29 11:03:34 GMT 2007


On Thu, Mar 29, 2007 at 02:27:14AM -0700, Jeff Chimene wrote:
> Hi,
> 
> I was wondering if anyone has extended the Authentication tutorial
> example to handle the "redirect to original URI" concept requested
> in this thread: http://www.gossamer-threads.com/lists/catalyst/users/11676
> 
> Does that suggested answer work with the implementation in
> Catalyst::Manual::Tutorial::Authentication? It looks like one would
> update the "end" method in the login controller to implement this technique?

I just have:

 sub login_if_required {
    my ($c, $message) = @_;

    if( not $c->is_logged_in($c) ) {
        # make sure we return here after a successful login
        $c->session->{after_login} = $c->request->uri();
        # set an informative message to display on the login screen
        if (defined $message) {
            $c->session->{login_message} = $message;
        }
        # send the user to the login screen
        $c->response->redirect( $c->uri_for('/user/login') );
        return;
    }
 }

in MyApp.pm and

	# if we've stored somewhere to go after we log-in, got there now
	if ( $c->session->{after_login} ) {
		$c->response->redirect( delete $c->session->{after_login} );
	}

after a successful login.

It's worked for me so far ... 
-- 
Chisel Wright
e: chisel at herlpacker.co.uk
w: http://www.herlpacker.co.uk/

  IRC is just multiplayer notepad.



More information about the Catalyst mailing list