[Catalyst] Saving redirect URL in flash not sticking through login process

will trillich will.trillich at serensoft.com
Mon Jan 24 04:52:42 GMT 2011


The flash is moved to the stash after the redirect, and then it's gone after
that, right?

What we do is stuff the intended destination into the session and then pull
it from there:

sub login : Chained('/') PathPart('login') Args(0) {
    my ( $self, $c ) =3D @_;

    my $form =3D Spill::Form::Login->new( action =3D> $c->uri_for('/login')=
 );

    $c->stash(
        template =3D> 'login.tt2',
        form     =3D> $form,
    );

    if ( $c->action ne 'login' ) {
        # Stuff destination into session for later redirect if user
authenticates
*        $c->session->{redirect} =3D $c->req->uri->as_string;*
    }

...then, later, after authenticating...

            my $go =3D *delete( $c->session->{redirect} )* ||
$c->req->headers->referer;
            $go =3D '/' if $go =3D~ /\blog(in|out)\b/;
            $c->res->redirect( $go );
            $c->detach;


On Sun, Jan 23, 2011 at 8:27 PM, Eric Berg <eberg at bergbrains.com> wrote:

> If a user submits a certain form without being logged in, I flash the
> current URL, save the params in the session, and redirect them to the log=
in.
>
> In my Login controller, I look for $c->flash->{redirect_url} and redirect
> them back to that URL.
>
> The problem is that that flash entry is gone after the user submits the
> login form.  I logged out the redirect URL at the beginning of my login
> routine and it comes through the first time, but even if I don't access it
> via the log statement, that redirect_url key is not there in the flash wh=
en
> the user submits the login form with their credentials.
>
> I've tried resetting $c->flash->{redirect_url} in the login routine and
> also tried $c->keep_flash( qw( redirect_url )) in the login routine, but =
no
> go.
>
> Any thoughts on what I might be doing wrong?
>
> Eric
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>



-- =

The first step towards getting somewhere is to decide that you are not going
to stay where you are.  -- J.P.Morgan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110123/891bb=
876/attachment.htm


More information about the Catalyst mailing list