FAQ
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 login.

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 when 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

Search Discussions

  • Will Trillich at Jan 24, 2011 at 4:52 am
    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 ) = @_;

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

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

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

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

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

    On Sun, Jan 23, 2011 at 8:27 PM, Eric Berg 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 login.

    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 when
    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@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/891bb876/attachment.htm
  • Eric Berg at Jan 24, 2011 at 4:58 am
    Thanks, Will. That I figured that would work, but I thought that the
    flash was the right way to do it -- especially with the automatic
    cleanup, so I was holding off on trying that.

    Why doesn't flash work across these multiple requests? I thought that
    was the whole idea of flash vs. stash.

    Eric
    On 1/23/11 11:52 PM, will trillich wrote:
    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 ) = @_;

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

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

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

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

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


    On Sun, Jan 23, 2011 at 8:27 PM, Eric Berg 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 login.

    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 when 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@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


    _______________________________________________
    List: Catalyst@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/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20110123/6b6e3414/attachment.htm
  • Will Trillich at Jan 24, 2011 at 5:36 am
    I think stash is the ephemeral one-shot hashref, whereas flash is the
    next-request's preloaded stash. That is, you can load up your flash with
    whatever you need, and then do a full $c->res->redirect() somewhere -- which
    fires off a browser redirect and a new request -- and your then-stash will
    have all the goodies you plopped in there.

    And, being the stash, it's all wiped out when the request is done. So a
    follow-up request (or redirect) would either have an empty stash, or it'd
    require the second request-handling routines to stuff things into flash
    (again).

    So it's not that "flash" is permanent, it's not. It's just a pre-load for
    the next-request's short-lived stash.

    On Sun, Jan 23, 2011 at 10:58 PM, Eric Berg wrote:

    Thanks, Will. That I figured that would work, but I thought that the
    flash was the right way to do it -- especially with the automatic cleanup,
    so I was holding off on trying that.

    Why doesn't flash work across these multiple requests? I thought that was
    the whole idea of flash vs. stash.

    Eric


    On 1/23/11 11:52 PM, will trillich wrote:

    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 ) = @_;

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

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

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

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

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

    On Sun, Jan 23, 2011 at 8:27 PM, Eric Berg 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 login.

    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 when
    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@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


    _______________________________________________
    List: Catalyst@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/



    _______________________________________________
    List: Catalyst@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/9c4af42c/attachment.htm
  • Will Trillich at Jan 24, 2011 at 5:41 am
    Altho the implications here
    http://search.cpan.org/~bobtfish/Catalyst-Plugin-Session-0.31/lib/Catalyst/Plugin/Session.pm#METHODS
    are that you can do multiple redirects with one $c->flash -- to wit:

    """
    The flash data will be cleaned up only on requests on which actually use
    $c->flash (thus allowing multiple redirections), and the policy is to delete
    all the keys which haven't changed since the flash data was loaded at the
    end of every request.
    """

    We just treat it as a preloaded stash, and that seems to work fine for us.
    If we want a more permanent chunk of data, we inject it into $c->session.


    On Sun, Jan 23, 2011 at 11:36 PM, will trillich wrote:

    I think stash is the ephemeral one-shot hashref, whereas flash is the
    next-request's preloaded stash. That is, you can load up your flash with
    whatever you need, and then do a full $c->res->redirect() somewhere -- which
    fires off a browser redirect and a new request -- and your then-stash will
    have all the goodies you plopped in there.

    And, being the stash, it's all wiped out when the request is done. So a
    follow-up request (or redirect) would either have an empty stash, or it'd
    require the second request-handling routines to stuff things into flash
    (again).

    So it's not that "flash" is permanent, it's not. It's just a pre-load for
    the next-request's short-lived stash.

    On Sun, Jan 23, 2011 at 10:58 PM, Eric Berg wrote:

    Thanks, Will. That I figured that would work, but I thought that the
    flash was the right way to do it -- especially with the automatic cleanup,
    so I was holding off on trying that.

    Why doesn't flash work across these multiple requests? I thought that was
    the whole idea of flash vs. stash.

    Eric


    On 1/23/11 11:52 PM, will trillich wrote:

    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 ) = @_;

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

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

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

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

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

    On Sun, Jan 23, 2011 at 8:27 PM, Eric Berg 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 login.

    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 when
    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@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


    _______________________________________________
    List: Catalyst@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/



    _______________________________________________
    List: Catalyst@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


    --
    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/bbc8c88c/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJan 24, '11 at 2:27a
activeJan 24, '11 at 5:41a
posts5
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Will Trillich: 3 posts Eric Berg: 2 posts

People

Translate

site design / logo © 2022 Grokbase