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

Jeff Chimene jchimene at gmail.com
Thu Mar 29 17:13:31 GMT 2007


Chisel Wright wrote:
> 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 ... 
>   

Thanks, I'll give that a try.

As a side question, why does this particular technique use redirect()?
As opposed to, e.g. detach()?

Cheers,
jec




More information about the Catalyst mailing list