FAQ
Hi,

If the user wants to access a restricted zone and it is redirected to the
login page, which is the recommended way of redirecting him back to the
original URL?

I know that I could create a hidden field in the login form and put the
request URL in that field, and after the login, make a redirect to that URL,
but I just want to know if there is a more easier way.

Thanks.

Octavian

Search Discussions

  • Marc Logghe at Dec 30, 2006 at 11:21 am
    -----Oorspronkelijk bericht-----
    Van: Octavian Rasnita
    Verzonden: za 30-12-2006 11:38
    Aan: catalyst@lists.rawmode.org
    Onderwerp: [Catalyst] redirection to the original URI

    Hi,

    If the user wants to access a restricted zone and it is redirected to the
    login page, which is the recommended way of redirecting him back to the
    original URL?

    I know that I could create a hidden field in the login form and put the
    request URL in that field, and after the login, make a redirect to that URL,
    but I just want to know if there is a more easier way.

    Thanks.

    Octavian


    Hi Octavian,
    instead of putting the URL in a hidden field, you can put it in the session hash.
    HTH,
    Marc
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: not available
    Type: application/ms-tnef
    Size: 2675 bytes
    Desc: not available
    Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20061230/5c5fffda/attachment.bin
  • Fayland Lam at Jan 1, 2007 at 5:46 am

    Octavian Rasnita wrote:
    Hi,

    If the user wants to access a restricted zone and it is redirected to
    the login page, which is the recommended way of redirecting him back to
    the original URL?

    I know that I could create a hidden field in the login form and put the
    request URL in that field, and after the login, make a redirect to that
    URL, but I just want to know if there is a more easier way.
    well I would put such code in the sub end : Private {

    if ($c->res->location) {
    # for login using!
    if ($c->res->location =~ /^\/login/) {
    my $location = '/login?referer=/' . $c->req->path;
    $location .= '?' . uri_escape($c->req->uri->query) if
    ($c->req->uri->query);
    $c->res->location($location);
    }
    return 1;
    }

    that would be much easier.
    Thanks.

    Octavian


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/

    --
    Fayland Lam // http://www.fayland.org/
  • Thomas Hartman at Jan 1, 2007 at 7:09 am
    Do you mean Response::redirect() rather than Response::location()? I
    couldn't find anything about the location method in

    http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7006/lib/Catalyst/Response.pm

    Or is this a newer/older version than what's current on cpan?

    2007/1/1, Fayland Lam <fayland@gmail.com>:
    Octavian Rasnita wrote:
    Hi,

    If the user wants to access a restricted zone and it is redirected to
    the login page, which is the recommended way of redirecting him back to
    the original URL?

    I know that I could create a hidden field in the login form and put the
    request URL in that field, and after the login, make a redirect to that
    URL, but I just want to know if there is a more easier way.
    well I would put such code in the sub end : Private {

    if ($c->res->location) {
    # for login using!
    if ($c->res->location =~ /^\/login/) {
    my $location = '/login?referer=/' . $c->req->path;
    $location .= '?' . uri_escape($c->req->uri->query) if
    ($c->req->uri->query);
    $c->res->location($location);
    }
    return 1;
    }

    that would be much easier.
    Thanks.

    Octavian


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/

    --
    Fayland Lam // http://www.fayland.org/

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
  • Thomas Hartman at Jan 1, 2007 at 7:18 am
    Actually I see now that the location method is mentioned in the code

    http://search.cpan.org/src/SRI/Catalyst-5.61/lib/Catalyst/Response.pm

    Just not in the documentation. Indeed, it seems only to be used by the
    redirect() method.

    Couldn't you just then use Response::redirect here?

    If my understanding is correct, by using features not advertised in
    the interface (ie, the module documentation), it's more likely to be
    broken on upgrade.



    2007/1/1, Thomas Hartman <thomashartman1@googlemail.com>:
    Do you mean Response::redirect() rather than Response::location()? I
    couldn't find anything about the location method in

    http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7006/lib/Catalyst/Response.pm

    Or is this a newer/older version than what's current on cpan?

    2007/1/1, Fayland Lam <fayland@gmail.com>:
    Octavian Rasnita wrote:
    Hi,

    If the user wants to access a restricted zone and it is redirected to
    the login page, which is the recommended way of redirecting him back to
    the original URL?

    I know that I could create a hidden field in the login form and put the
    request URL in that field, and after the login, make a redirect to that
    URL, but I just want to know if there is a more easier way.
    well I would put such code in the sub end : Private {

    if ($c->res->location) {
    # for login using!
    if ($c->res->location =~ /^\/login/) {
    my $location = '/login?referer=/' . $c->req->path;
    $location .= '?' . uri_escape($c->req->uri->query) if
    ($c->req->uri->query);
    $c->res->location($location);
    }
    return 1;
    }

    that would be much easier.
    Thanks.

    Octavian


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/

    --
    Fayland Lam // http://www.fayland.org/

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
  • Fayland Lam at Jan 1, 2007 at 11:49 am

    Thomas Hartman wrote:
    Actually I see now that the location method is mentioned in the code

    http://search.cpan.org/src/SRI/Catalyst-5.61/lib/Catalyst/Response.pm

    Just not in the documentation. Indeed, it seems only to be used by the
    redirect() method.

    Couldn't you just then use Response::redirect here?

    If my understanding is correct, by using features not advertised in
    the interface (ie, the module documentation), it's more likely to be
    broken on upgrade.
    well, we used a lot of such code:
    return $c->res->redirect('/login') unless ($c->user_exists);
    but Catalyst treats redirect inside, so the $c->req->referer may be not
    what u want. we just can't redirect to the referer.

    mm, so I guess my solution can handle it correctly.


    2007/1/1, Thomas Hartman <thomashartman1@googlemail.com>:
    Do you mean Response::redirect() rather than Response::location()? I
    couldn't find anything about the location method in

    http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7006/lib/Catalyst/Response.pm


    Or is this a newer/older version than what's current on cpan?

    2007/1/1, Fayland Lam <fayland@gmail.com>:
    Octavian Rasnita wrote:
    Hi,

    If the user wants to access a restricted zone and it is redirected to
    the login page, which is the recommended way of redirecting him
    back to
    the original URL?

    I know that I could create a hidden field in the login form and
    put the
    request URL in that field, and after the login, make a redirect to
    that
    URL, but I just want to know if there is a more easier way.
    well I would put such code in the sub end : Private {

    if ($c->res->location) {
    # for login using!
    if ($c->res->location =~ /^\/login/) {
    my $location = '/login?referer=/' . $c->req->path;
    $location .= '?' . uri_escape($c->req->uri->query) if
    ($c->req->uri->query);
    $c->res->location($location);
    }
    return 1;
    }

    that would be much easier.
    Thanks.

    Octavian


    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.rawmode.org/

    --
    Fayland Lam // http://www.fayland.org/

    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive:
    http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/
    _______________________________________________
    List: Catalyst@lists.rawmode.org
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
    Dev site: http://dev.catalyst.perl.org/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedDec 30, '06 at 10:38a
activeJan 1, '07 at 11:49a
posts6
users4
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase