Message from discussion
Authenticating Routes
Received: by 10.66.72.134 with SMTP id d6mr1791146pav.20.1349417959821;
Thu, 04 Oct 2012 23:19:19 -0700 (PDT)
X-BeenThere: mojolicious@googlegroups.com
Received: by 10.68.189.162 with SMTP id gj2ls13664962pbc.6.gmail; Thu, 04 Oct
2012 23:19:18 -0700 (PDT)
Received: by 10.68.216.202 with SMTP id os10mr1012866pbc.17.1349417958748;
Thu, 04 Oct 2012 23:19:18 -0700 (PDT)
Date: Thu, 4 Oct 2012 23:19:18 -0700 (PDT)
From: Amit <am...@rae-consulting.com>
To: mojolicious@googlegroups.com
Cc: alis...@alisterwest.com
Message-Id: <415c0484-6cc9-49f4-a78b-0b8a75e8d46e@googlegroups.com>
In-Reply-To: <CALy2Nv8fYSrDqGVKaEVGzyWKHabcp4YhbRF53rN+WpnqTyii+Q@mail.gmail.com>
References: <31610ff6-6870-48ab-b90d-1c8e6782a096@googlegroups.com>
<CAKTcQ96TnSVw7N-9Vyk1_MkdsP4MP8Qd0Q-QdniB4Tir0rmAig@mail.gmail.com>
<CAKTcQ95xn50GrAkHCtQ-iM=uVy7WHdOr0ibgX_qttODBd6FW+Q@mail.gmail.com>
<f5b91f53-20ea-4ceb-b826-763352495be1@googlegroups.com>
<SNT134-W211D312ED996C1407BCD7ED0C60@phx.gbl>
<20e43211-cf92-479c-b1d5-23200aa94707@googlegroups.com>
<58fcbb1b-5695-4ffc-b699-e5fce3f3bff9@googlegroups.com>
<b270fcca-ede6-42f5-b01a-5a5ec20e3c16@googlegroups.com>
<SNT134-W37068B15863F7AA0B65332D0C40@phx.gbl>
<2dc8b9c2-f9fe-4512-93de-c6ae440ab6e3@googlegroups.com>
<f291a113-c32f-44f5-942a-01ee170bb0d2@googlegroups.com>
<Pine.LNX.4.64.1210041036430.20086@e-smith.charlieb.ott.istop.com>
<be18d7ae-de03-4816-827b-e5bc906904c3@googlegroups.com>
<CALy2Nv-KUiv+CWF5EXowWUrS5fjwvx-KOp8--GPODzWnqAMwJA@mail.gmail.com>
<3f41ac4e-f02c-4579-9fc6-17da5e75d418@googlegroups.com>
<CALy2Nv8fYSrDqGVKaEVGzyWKHabcp4YhbRF53rN+WpnqTyii+Q@mail.gmail.com>
Subject: Re: [Mojolicious] Authenticating Routes
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_335_7431746.1349417958202"
------=_Part_335_7431746.1349417958202
Content-Type: multipart/alternative;
boundary="----=_Part_336_15766791.1349417958202"
------=_Part_336_15766791.1349417958202
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Thanks a lot Alister. It worked fine. :)
Thanks once again.
Regards,
Amit Khurana
On Thursday, October 4, 2012 11:18:22 PM UTC+5:30, Alister West wrote:
>
> Hi, here is a working example using a bridge.
>
> #!/usr/bin/env perl
> use Mojolicious::Lite;
> my $self = app();
>
> my $public = $self->routes;
>
> $public->route("/" )->to( cb => sub { shift->render(text => "to
> slash\n") });
>
> $public->route("/main" )->to( cb => sub {
> my $self = shift;
> $self->render( text => "to Main::index (". $self->session('user')
> .")\n");
> });
>
> $public->get("/login" )->to( cb => sub {
> my $self = shift;
> $self->session( user => 'Bender');
> $self->render(text => "Logged in as Bender\n")
> });
>
> $public->get("/logout")->to( cb => sub {
> my $self = shift;
> $self->session( user => '' );
> $self->render(text => "You are logged out\n")
> });
>
> my $auth = $public->bridge->to(cb => sub { my $self = shift;
> return 1 if $self->session('user');
> # do a redirect to /login here.
> $self->render( text => 'You are not logged in');
> return;
> });
>
> $auth->get("/foo")->to( cb => sub { shift->render(text => "this is
> foo\n"); });
>
> $self->start;
>
>
>
> ~~
> c|_| alisterwest.com - mmm coffee!
>
>
> On 4 October 2012 09:21, Amit <am...@rae-consulting.com <javascript:>>
> wrote:
> > Hi Alister,
> >
> > Thanks for the prompt reply. I tried. I also added more routes to the
> $auth,
> > but those routes are not working. I mean, after,
> >
> > my $pubic = $self->routes;
> >
> > $public->route('/')->to('main#index');
> > $public->route('/main')->to('main#index');
> > $public->post('/login')->to('main#post_login');
> > $public->post('/logout')->to('main#logout');
> >
> > my $auth = $public->bridge->to('UserAuthUtil#check');
> > $auth->post('/main')->to('main#post_login');
> >
> > I added: $auth->route('/foo')->to('foo#bar');
> >
> > But its not working. I am able to login but accessing any link or
> putting
> > any other page address directly in URL throws me following error:
> >
> > Page not found... yet!
> >
> > None of these routes matched your GET request for /foo, maybe you need
> to
> > add a new one?
> >
> >
> >
> > Regards,
> >
> > Amit
> >
> >
> > On Thursday, October 4, 2012 9:32:08 PM UTC+5:30, Alister West wrote:
> >>
> >> It seems like your providing your routes backwards. This is probably
> >> not what you want (but is what you have).
> >>
> >> Unauthenticated (called $auth??)
> >> /main (get + post)
> >>
> >> Authenticated (called $r ??)
> >> /
> >> /main
> >> /login
> >> /logout
> >>
> >> Try:
> >> my $pubic = $self->routes;
> >>
> >> $public->route('/')->to('main#index');
> >> $public->route('/main')->to('main#index');
> >> $public->post('/login')->to('main#post_login');
> >> $public->post('/logout')->to('main#logout');
> >>
> >> my $auth = $public->bridge->to('UserAuthUtil#check');
> >> $auth->post('/main')->to('main#post_login');
> >>
> >>
> >> ~~
> >> c|_| alisterwest.com - mmm coffee!
> >>
> >>
> >> On 4 October 2012 08:39, Amit <am...@rae-consulting.com> wrote:
> >> > Oh yeah thats right. The earlier suggestion given by byterock is not
> >> > working. I mean, I tried that way but its not working.
> >> >
> >> > Please suggest. The sample code is provided in my previous post. I'll
> >> > again
> >> > provide it.
> >> >
> >> > My Login and logout form is the same one (main). It has a small
> section
> >> > on
> >> > top which contains credential textboxes and login button. When the
> user
> >> > is
> >> > successfully logged in, that section is hidden and logout button
> >> > appears.
> >> > Code:
> >> >
> >> > my $auth = $self->routes;
> >> > $auth->route('/main')->via('get')->to('main#index');
> >> > $auth->route('/main')->via('post')->to('main#post_login');
> >> >
> >> > my $r = $auth->bridge->to('UserAuthUtil#check');
> >> >
> >> > $r->route('/')->to('main#index');
> >> > $r->route('/main')->to('main#index');
> >> > $r->post('/login')->to('main#post_login');
> >> > $r->post('/logout')->to('main#logout');
> >> >
> >> > There are more routes need to be added in $r after this.
> >> >
> >> > Thanks & Regards,
> >> >
> >> > Amit Khurana
> >> >
> >> >
> >> > On Thursday, October 4, 2012 8:08:08 PM UTC+5:30, Charlie Brady
> wrote:
> >> >>
> >> >>
> >> >> If you want some help, I suggest you provide more detail that "it
> >> >> didn't
> >> >> worked" and "its[ not working".
> >> >>
> >> >> On Thu, 4 Oct 2012, Amit wrote:
> >> >>
> >> >> > Hi All,
> >> >> >
> >> >> > I apologize to reopen this thread again. Due to some other
> priority
> >> >> > work, I
> >> >> > had to leave this but now I am back again on this. I tried the way
> >> >> > byterock
> >> >> > explained. But it didn't worked. I'll again explain my form with
> >> >> > code.
> >> >> >
> >> >> > My Login and logout form is the same one (main). It has a small
> >> >> > section
> >> >> > on
> >> >> > top which contains credential textboxes and login button. When the
> >> >> > user
> >> >> > is
> >> >> > successfully logged in, that section is hidden and logout button
> >> >> > appears.
> >> >> > Code:
> >> >> >
> >> >> > my $auth = $self->routes;
> >> >> > $auth->route('/main')->via('get')->to('main#index');
> >> >> > $auth->route('/main')->via('post')->to('main#post_login');
> >> >> > #
> >> >> > my $r = $auth->bridge->to('UserAuthUtil#check');
> >> >> >
> >> >> > $r->route('/')->to('main#index');
> >> >> > $r->route('/main')->to('main#index');
> >> >> > $r->post('/login')->to('main#post_login');
> >> >> > $r->post('/logout')->to('main#logout');
> >> >> >
> >> >> > Not sure what I am doing wrong here but its not working.
> >> >> >
> >> >> > Thanks & Regards,
> >> >> >
> >> >> > Amit Khurana
> >> >> >
> >> >> > On Friday, August 3, 2012 10:48:38 AM UTC+5:30, Amit wrote:
> >> >> > >
> >> >> > > Thanks all for your valuable inputs.
> >> >> > >
> >> >> > > Amit
> >> >> > >
> >> >> > > On Wednesday, August 1, 2012 4:30:41 PM UTC+5:30, byterock
> wrote:
> >> >> > >>
> >> >> > >>
> >> >> > >> Try if like i shoewed before with a named route to some place.
> A
> >> >> > >> general
> >> >> > >> catchall or redirect to '/' is never a good idea
> >> >> > >>
> >> >> > >> so in your controller you would have something like this
> >> >> > >>
> >> >> > >> $r->route('/login') ->via('get')
> >> >> > >> ->to('authn#form')->name('authn_form');
> >> >> > >> $r->route('/login') ->via('post')->to('authn#login');
> >> >> > >> my $rb = $r->bridge->to('authn#check');
> >> >> > >> $mb->route('/main')->to('main#index');
> >> >> > >>
> >> >> > >> and in Authn.pm
> >> >> > >>
> >> >> > >> sub check {
> >> >> > >> my $self = shift;
> >> >> > >> $self->redirect_to('authn_form') and return 0
> >> >> > >> unless($self->is_user_authenticated);
> >> >> > >> return 1;
> >> >> > >> }
> >> >> > >>
> >> >> > >>
> >> >> > >>
> >> >> > >> ________________________________
> >> >> > >> > Date: Tue, 31 Jul 2012 23:15:17 -0700
> >> >> > >> > From:
> >> >> > >> > To: mojol...@googlegroups.com
> >> >> > >> > Subject: Re: [Mojolicious] Authenticating Routes
> >> >> > >> >
> >> >> > >> > Hi Jay,
> >> >> > >> >
> >> >> > >> > I had tried that also. But, I have this in my check():
> >> >> > >> >
> >> >> > >> > sub check {
> >> >> > >> > my $self = shift;
> >> >> > >> > $self->redirect_to("/") and return 0
> >> >> > >> > unless($self->is_user_authenticated);
> >> >> > >> > return 1;
> >> >> > >> > }
> >> >> > >> >
> >> >> > >> > So when I enter credentials and click Submit, it calls check
> >> >> > >> > first
> >> >> > >> > and
> >> >> > >> > redirects me back to the root. i.e. it does not call
> >> >> > >> > "post_login"
> >> >> > >> > method.
> >> >> > >> >
> >> >> > >> > Thanks,
> >> >> > >> >
> >> >> > >> > Amit
> >> >> > >> >
> >> >> > >> > On Tuesday, July 31, 2012 7:02:52 PM UTC+5:30, jay m wrote:
> >> >> > >> > the page with your login form needs to be accessible by
> >> >> > >> > unauthenticated
> >> >> > >> > users. the way you have it now, when you redirect to / it
> sends
> >> >> > >> > you
> >> >> > >> > back through the bridge again, and again, and again...
> something
> >> >> > >> > like
> >> >> > >> > this will work:
> >> >> > >> >
> >> >> > >> > my $public = $self->routes;
> >> >> > >> > my $r = $public->bridge->to('main#check');
> >> >> > >> > $public->route('/')->to('main#index');
> >> >> > >> > $r->route('/main')->to('main#index');
> >> >> > >> >
> >> >> > >> >
> >> >> > >> > On Tuesday, July 31, 2012 3:32:54 AM UTC-4, Amit wrote:
> >> >> > >> > Thanks John and David. Actually my main has a section which
> >> >> > >> > renders
> >> >> > >> > another small login section based on user is authenticated or
> >> >> > >> > not.
> >> >> > >> > So I
> >> >> > >> > login page is the same as my logout page. I made that small
> >> >> > >> > change
> >> >> > >> > in
> >> >> > >> > the check() but now I am getting too many redirects error.
> >> >> > >> >
> >> >> > >> > I have:
> >> >> > >> >
> >> >> > >> > my $auth = $self->routes;
> >> >> > >> > my $r = $auth->bridge('/')->to('main#check');
> >> >> > >> > $r->route('/')->to('main#index');
> >> >> > >> > $r->route('/main')->to('main#index');
> >> >> > >> >
> >> >> > >> > Last 2 lines of code, because I want user to logon and
> display
> >> >> > >> > information upon successful login. And second is when user
> >> >> > >> > clicks
> >> >> > >> > on
> >> >> > >> > menu "Main".
> >> >> > >> >
> >> >> > >> > So if in check(), I put:
> >> >> > >> >
> >> >> > >> > $self->redirect_to("/") and return 0
> >> >> > >> > unless($self->is_user_authenticated); , or
> >> >> > >> > $self->redirect_to("/main") and return 0
> >> >> > >> > unless($self->is_user_authenticated);
> >> >> > >> >
> >> >> > >> > I get too many redirects error.
> >> >> > >> >
> >> >> > >> > Thanks in advance
> >> >> > >> >
> >> >> > >> > Amit
> >> >> > >> >
> >> >> > >> > On Monday, July 30, 2012 4:18:37 PM UTC+5:30, byterock wrote:
> >> >> > >> >
> >> >> > >> > that won't realy work on a bridge as a bridge just goes to
> the
> >> >> > >> > controller it is not condtional route
> >> >> > >> >
> >> >> > >> > try this in you check
> >> >> > >> >
> >> >> > >> > sub check {
> >> >> > >> > my $self = shift;
> >> >> > >> > $self->redirect_to('not_authn') and return 0
> >> >> > >> > unless($self->is_user_authenticated);
> >> >> > >> > return 1;
> >> >> > >> > }
> >> >> > >> >
> >> >> > >> > where not_authn is a template or named route that you want
> your
> >> >> > >> > user to
> >> >> > >> > go to when they are not authenticated
> >> >> > >> >
> >> >> > >> > A condtionaly controller works like this
> >> >> > >> >
> >> >> > >> > $r->route('/home')->over(authenticated =>
> >> >> > >> > 1)->to('example#home')->name('home');
> >> >> > >> >
> >> >> > >> > however what you want(catch all) is what you have now with
> the
> >> >> > >> > small
> >> >> > >> > change above
> >> >> > >> >
> >> >> > >> > Cheers
> >> >> > >> > John
> >> >> > >> >
> >> >> > >> > ________________________________
> >> >> > >> > > Date: Mon, 30 Jul 2012 03:37:07 -0700
> >> >> > >> > > From:
> >> >> > >> > > To:
> >> >> > >> > > mojol...@googlegroups.com<mailto:mojol...@googlegroups.com>
>
> >> >> > >>
> >> >> > >> > > Subject: Re: [Mojolicious] Authenticating Routes
> >> >> > >> > >
> >> >> > >> > > Thanks David for the info. Following is the code inside
> check:
> >> >> > >> > >
> >> >> > >> > > sub check {
> >> >> > >> > > my $self = shift;
> >> >> > >> > > return 0 unless($self->is_user_authenticated);
> >> >> > >> > > return 1;
> >> >> > >> > > }
> >> >> > >> > >
> >> >> > >> > > On Monday, July 30, 2012 1:26:51 PM UTC+5:30, David Oswald
> >> >> > >> > > wrote:
> >> >> > >> > > > 'main', Main::check, main::check, Main::check,
> >> >> > >> > > > main::check code (pay attention to capitalization).
> >> >> > >> > >
> >> >> > >> > > You see, even after talking about it, I still am getting it
> >> >> > >> > > mixed
> >> >> > >> > > up.
> >> >> > >> > > 'main' vs 'Main'. ...that controller name is begging to be
> >> >> > >> > > changed to
> >> >> > >> > > something that doesn't resemble Perl's default package. ;)
> >> >> > >> > >
> >> >> > >> > >
> >> >> > >> > > --
> >> >> > >> > >
> >> >> > >> > > David Oswald
> >> >> > >> > >
> >> >> > >> > >
> >> >> > >> > > --
> >> >> > >> > > You received this message because you are subscribed to the
> >> >> > >> > > Google
> >> >> > >> > > Groups "Mojolicious" group.
> >> >> > >> > > To view this discussion on the web visit
> >> >> > >> > > https://groups.google.com/d/msg/mojolicious/-/_uy0fIj3haIJ.
>
> >> >> > >> > > To post to this group, send email to
> >> >> > >> > mojol...@googlegroups.com<mailto:mojol...@googlegroups.com>.
> >> >> > >> > > To unsubscribe from this group, send email to
> >> >> > >> > >
> >> >> > >> > mojolicious...@googlegroups.com<mailto:
> >> >> > >> mojolicious%...@googlegroups.com>.
> >> >> > >> > > For more options, visit this group at
> >> >> > >> > > http://groups.google.com/group/mojolicious?hl=en.
> >> >> > >> >
> >> >> > >> > --
> >> >> > >> > You received this message because you are subscribed to the
> >> >> > >> > Google
> >> >> > >> > Groups "Mojolicious" group.
> >> >> > >> > To view this discussion on the web visit
> >> >> > >> > https://groups.google.com/d/msg/mojolicious/-/AnH1vfcVzzoJ.
> >> >> > >> > To post to this group, send email to
> mojol...@googlegroups.com.
> >> >> > >> > To unsubscribe from this group, send email to
> >> >> > >> > mojolicious...@googlegroups.com.
> >> >> > >> > For more options, visit this group at
> >> >> > >> > http://groups.google.com/group/mojolicious?hl=en.
> >> >> > >>
> >> >> > >
> >> >> > >
> >> >> >
> >> >> >
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> > Groups
> >> > "Mojolicious" group.
> >> > To view this discussion on the web visit
> >> > https://groups.google.com/d/msg/mojolicious/-/y09M4gItKSEJ.
> >> >
> >> > To post to this group, send email to mojol...@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > mojolicious...@googlegroups.com.
> >> > For more options, visit this group at
> >> > http://groups.google.com/group/mojolicious?hl=en.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Mojolicious" group.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msg/mojolicious/-/LiM2MGKGwDQJ.
> >
> > To post to this group, send email to mojol...@googlegroups.com<javascript:>.
>
> > To unsubscribe from this group, send email to
> > mojolicious...@googlegroups.com <javascript:>.
> > For more options, visit this group at
> > http://groups.google.com/group/mojolicious?hl=en.
>
------=_Part_336_15766791.1349417958202
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
Thanks a lot Alister. It worked fine. :)<div><br></div><div>Thanks once again.</div><div><br></div><div>Regards,</div><div><br></div><div>Amit Khurana<br><br>On Thursday, October 4, 2012 11:18:22 PM UTC+5:30, Alister West wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi, here is a working example using a bridge.
<br>
<br>#!/usr/bin/env perl
<br>use Mojolicious::Lite;
<br>my $self = app();
<br>
<br>my $public = $self->routes;
<br>
<br>$public->route("/" )->to( cb => sub { shift->render(text => "to
<br>slash\n") });
<br>
<br>$public->route("/main" )->to( cb => sub {
<br> my $self = shift;
<br> $self->render( text => "to Main::index (". $self->session('user') .")\n");
<br>});
<br>
<br>$public->get("/login" )->to( cb => sub {
<br> my $self = shift;
<br> $self->session( user => 'Bender');
<br> $self->render(text => "Logged in as Bender\n")
<br>});
<br>
<br>$public->get("/logout")->to( cb => sub {
<br> my $self = shift;
<br> $self->session( user => '' );
<br> $self->render(text => "You are logged out\n")
<br>});
<br>
<br>my $auth = $public->bridge->to(cb => sub { my $self = shift;
<br> return 1 if $self->session('user');
<br> # do a redirect to /login here.
<br> $self->render( text => 'You are not logged in');
<br> return;
<br> });
<br>
<br>$auth->get("/foo")->to( cb => sub { shift->render(text => "this is foo\n"); });
<br>
<br>$self->start;
<br>
<br>
<br>
<br>~~
<br> c|_| <a href="http://alisterwest.com" target="_blank">alisterwest.com</a> - mmm coffee!
<br>
<br>
<br>On 4 October 2012 09:21, Amit <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="4dht-K1RyacJ">am...@rae-consulting.com</a>> wrote:
<br>> Hi Alister,
<br>>
<br>> Thanks for the prompt reply. I tried. I also added more routes to the $auth,
<br>> but those routes are not working. I mean, after,
<br>>
<br>> my $pubic = $self->routes;
<br>>
<br>> $public->route('/')->to('main#<wbr>index');
<br>> $public->route('/main')->to('<wbr>main#index');
<br>> $public->post('/login')->to('<wbr>main#post_login');
<br>> $public->post('/logout')->to('<wbr>main#logout');
<br>>
<br>> my $auth = $public->bridge->to('<wbr>UserAuthUtil#check');
<br>> $auth->post('/main')->to('<wbr>main#post_login');
<br>>
<br>> I added: $auth->route('/foo')->to('foo#<wbr>bar');
<br>>
<br>> But its not working. I am able to login but accessing any link or putting
<br>> any other page address directly in URL throws me following error:
<br>>
<br>> Page not found... yet!
<br>>
<br>> None of these routes matched your GET request for /foo, maybe you need to
<br>> add a new one?
<br>>
<br>>
<br>>
<br>> Regards,
<br>>
<br>> Amit
<br>>
<br>>
<br>> On Thursday, October 4, 2012 9:32:08 PM UTC+5:30, Alister West wrote:
<br>>>
<br>>> It seems like your providing your routes backwards. This is probably
<br>>> not what you want (but is what you have).
<br>>>
<br>>> Unauthenticated (called $auth??)
<br>>> /main (get + post)
<br>>>
<br>>> Authenticated (called $r ??)
<br>>> /
<br>>> /main
<br>>> /login
<br>>> /logout
<br>>>
<br>>> Try:
<br>>> my $pubic = $self->routes;
<br>>>
<br>>> $public->route('/')->to('main#<wbr>index');
<br>>> $public->route('/main')->to('<wbr>main#index');
<br>>> $public->post('/login')->to('<wbr>main#post_login');
<br>>> $public->post('/logout')->to('<wbr>main#logout');
<br>>>
<br>>> my $auth = $public->bridge->to('<wbr>UserAuthUtil#check');
<br>>> $auth->post('/main')->to('<wbr>main#post_login');
<br>>>
<br>>>
<br>>> ~~
<br>>> c|_| <a href="http://alisterwest.com" target="_blank">alisterwest.com</a> - mmm coffee!
<br>>>
<br>>>
<br>>> On 4 October 2012 08:39, Amit <<a>am...@rae-consulting.com</a>> wrote:
<br>>> > Oh yeah thats right. The earlier suggestion given by byterock is not
<br>>> > working. I mean, I tried that way but its not working.
<br>>> >
<br>>> > Please suggest. The sample code is provided in my previous post. I'll
<br>>> > again
<br>>> > provide it.
<br>>> >
<br>>> > My Login and logout form is the same one (main). It has a small section
<br>>> > on
<br>>> > top which contains credential textboxes and login button. When the user
<br>>> > is
<br>>> > successfully logged in, that section is hidden and logout button
<br>>> > appears.
<br>>> > Code:
<br>>> >
<br>>> > my $auth = $self->routes;
<br>>> > $auth->route('/main')->via('<wbr>get')->to('main#index');
<br>>> > $auth->route('/main')->via('<wbr>post')->to('main#post_login');
<br>>> >
<br>>> > my $r = $auth->bridge->to('<wbr>UserAuthUtil#check');
<br>>> >
<br>>> > $r->route('/')->to('main#<wbr>index');
<br>>> > $r->route('/main')->to('main#<wbr>index');
<br>>> > $r->post('/login')->to('main#<wbr>post_login');
<br>>> > $r->post('/logout')->to('<wbr>main#logout');
<br>>> >
<br>>> > There are more routes need to be added in $r after this.
<br>>> >
<br>>> > Thanks & Regards,
<br>>> >
<br>>> > Amit Khurana
<br>>> >
<br>>> >
<br>>> > On Thursday, October 4, 2012 8:08:08 PM UTC+5:30, Charlie Brady wrote:
<br>>> >>
<br>>> >>
<br>>> >> If you want some help, I suggest you provide more detail that "it
<br>>> >> didn't
<br>>> >> worked" and "its[ not working".
<br>>> >>
<br>>> >> On Thu, 4 Oct 2012, Amit wrote:
<br>>> >>
<br>>> >> > Hi All,
<br>>> >> >
<br>>> >> > I apologize to reopen this thread again. Due to some other priority
<br>>> >> > work, I
<br>>> >> > had to leave this but now I am back again on this. I tried the way
<br>>> >> > byterock
<br>>> >> > explained. But it didn't worked. I'll again explain my form with
<br>>> >> > code.
<br>>> >> >
<br>>> >> > My Login and logout form is the same one (main). It has a small
<br>>> >> > section
<br>>> >> > on
<br>>> >> > top which contains credential textboxes and login button. When the
<br>>> >> > user
<br>>> >> > is
<br>>> >> > successfully logged in, that section is hidden and logout button
<br>>> >> > appears.
<br>>> >> > Code:
<br>>> >> >
<br>>> >> > my $auth = $self->routes;
<br>>> >> > $auth->route('/main')->via('<wbr>get')->to('main#index');
<br>>> >> > $auth->route('/main')->via('<wbr>post')->to('main#post_login');
<br>>> >> > #
<br>>> >> > my $r = $auth->bridge->to('<wbr>UserAuthUtil#check');
<br>>> >> >
<br>>> >> > $r->route('/')->to('main#<wbr>index');
<br>>> >> > $r->route('/main')->to('main#<wbr>index');
<br>>> >> > $r->post('/login')->to('main#<wbr>post_login');
<br>>> >> > $r->post('/logout')->to('main#<wbr>logout');
<br>>> >> >
<br>>> >> > Not sure what I am doing wrong here but its not working.
<br>>> >> >
<br>>> >> > Thanks & Regards,
<br>>> >> >
<br>>> >> > Amit Khurana
<br>>> >> >
<br>>> >> > On Friday, August 3, 2012 10:48:38 AM UTC+5:30, Amit wrote:
<br>>> >> > >
<br>>> >> > > Thanks all for your valuable inputs.
<br>>> >> > >
<br>>> >> > > Amit
<br>>> >> > >
<br>>> >> > > On Wednesday, August 1, 2012 4:30:41 PM UTC+5:30, byterock wrote:
<br>>> >> > >>
<br>>> >> > >>
<br>>> >> > >> Try if like i shoewed before with a named route to some place. A
<br>>> >> > >> general
<br>>> >> > >> catchall or redirect to '/' is never a good idea
<br>>> >> > >>
<br>>> >> > >> so in your controller you would have something like this
<br>>> >> > >>
<br>>> >> > >> $r->route('/login') ->via('get')
<br>>> >> > >> ->to('authn#form')->name('<wbr>authn_form');
<br>>> >> > >> $r->route('/login') ->via('post')->to('authn#<wbr>login');
<br>>> >> > >> my $rb = $r->bridge->to('authn#check');
<br>>> >> > >> $mb->route('/main')->to('main#<wbr>index');
<br>>> >> > >>
<br>>> >> > >> and in Authn.pm
<br>>> >> > >>
<br>>> >> > >> sub check {
<br>>> >> > >> my $self = shift;
<br>>> >> > >> $self->redirect_to('authn_<wbr>form') and return 0
<br>>> >> > >> unless($self->is_user_<wbr>authenticated);
<br>>> >> > >> return 1;
<br>>> >> > >> }
<br>>> >> > >>
<br>>> >> > >>
<br>>> >> > >>
<br>>> >> > >> _____________________________<wbr>___
<br>>> >> > >> > Date: Tue, 31 Jul 2012 23:15:17 -0700
<br>>> >> > >> > From:
<br>>> >> > >> > To: <a>mojol...@googlegroups.com</a>
<br>>> >> > >> > Subject: Re: [Mojolicious] Authenticating Routes
<br>>> >> > >> >
<br>>> >> > >> > Hi Jay,
<br>>> >> > >> >
<br>>> >> > >> > I had tried that also. But, I have this in my check():
<br>>> >> > >> >
<br>>> >> > >> > sub check {
<br>>> >> > >> > my $self = shift;
<br>>> >> > >> > $self->redirect_to("/") and return 0
<br>>> >> > >> > unless($self->is_user_<wbr>authenticated);
<br>>> >> > >> > return 1;
<br>>> >> > >> > }
<br>>> >> > >> >
<br>>> >> > >> > So when I enter credentials and click Submit, it calls check
<br>>> >> > >> > first
<br>>> >> > >> > and
<br>>> >> > >> > redirects me back to the root. i.e. it does not call
<br>>> >> > >> > "post_login"
<br>>> >> > >> > method.
<br>>> >> > >> >
<br>>> >> > >> > Thanks,
<br>>> >> > >> >
<br>>> >> > >> > Amit
<br>>> >> > >> >
<br>>> >> > >> > On Tuesday, July 31, 2012 7:02:52 PM UTC+5:30, jay m wrote:
<br>>> >> > >> > the page with your login form needs to be accessible by
<br>>> >> > >> > unauthenticated
<br>>> >> > >> > users. the way you have it now, when you redirect to / it sends
<br>>> >> > >> > you
<br>>> >> > >> > back through the bridge again, and again, and again... something
<br>>> >> > >> > like
<br>>> >> > >> > this will work:
<br>>> >> > >> >
<br>>> >> > >> > my $public = $self->routes;
<br>>> >> > >> > my $r = $public->bridge->to('main#<wbr>check');
<br>>> >> > >> > $public->route('/')->to('main#<wbr>index');
<br>>> >> > >> > $r->route('/main')->to('main#<wbr>index');
<br>>> >> > >> >
<br>>> >> > >> >
<br>>> >> > >> > On Tuesday, July 31, 2012 3:32:54 AM UTC-4, Amit wrote:
<br>>> >> > >> > Thanks John and David. Actually my main has a section which
<br>>> >> > >> > renders
<br>>> >> > >> > another small login section based on user is authenticated or
<br>>> >> > >> > not.
<br>>> >> > >> > So I
<br>>> >> > >> > login page is the same as my logout page. I made that small
<br>>> >> > >> > change
<br>>> >> > >> > in
<br>>> >> > >> > the check() but now I am getting too many redirects error.
<br>>> >> > >> >
<br>>> >> > >> > I have:
<br>>> >> > >> >
<br>>> >> > >> > my $auth = $self->routes;
<br>>> >> > >> > my $r = $auth->bridge('/')->to('main#<wbr>check');
<br>>> >> > >> > $r->route('/')->to('main#<wbr>index');
<br>>> >> > >> > $r->route('/main')->to('main#<wbr>index');
<br>>> >> > >> >
<br>>> >> > >> > Last 2 lines of code, because I want user to logon and display
<br>>> >> > >> > information upon successful login. And second is when user
<br>>> >> > >> > clicks
<br>>> >> > >> > on
<br>>> >> > >> > menu "Main".
<br>>> >> > >> >
<br>>> >> > >> > So if in check(), I put:
<br>>> >> > >> >
<br>>> >> > >> > $self->redirect_to("/") and return 0
<br>>> >> > >> > unless($self->is_user_<wbr>authenticated); , or
<br>>> >> > >> > $self->redirect_to("/main") and return 0
<br>>> >> > >> > unless($self->is_user_<wbr>authenticated);
<br>>> >> > >> >
<br>>> >> > >> > I get too many redirects error.
<br>>> >> > >> >
<br>>> >> > >> > Thanks in advance
<br>>> >> > >> >
<br>>> >> > >> > Amit
<br>>> >> > >> >
<br>>> >> > >> > On Monday, July 30, 2012 4:18:37 PM UTC+5:30, byterock wrote:
<br>>> >> > >> >
<br>>> >> > >> > that won't realy work on a bridge as a bridge just goes to the
<br>>> >> > >> > controller it is not condtional route
<br>>> >> > >> >
<br>>> >> > >> > try this in you check
<br>>> >> > >> >
<br>>> >> > >> > sub check {
<br>>> >> > >> > my $self = shift;
<br>>> >> > >> > $self->redirect_to('not_authn'<wbr>) and return 0
<br>>> >> > >> > unless($self->is_user_<wbr>authenticated);
<br>>> >> > >> > return 1;
<br>>> >> > >> > }
<br>>> >> > >> >
<br>>> >> > >> > where not_authn is a template or named route that you want your
<br>>> >> > >> > user to
<br>>> >> > >> > go to when they are not authenticated
<br>>> >> > >> >
<br>>> >> > >> > A condtionaly controller works like this
<br>>> >> > >> >
<br>>> >> > >> > $r->route('/home')->over(<wbr>authenticated =>
<br>>> >> > >> > 1)->to('example#home')->name('<wbr>home');
<br>>> >> > >> >
<br>>> >> > >> > however what you want(catch all) is what you have now with the
<br>>> >> > >> > small
<br>>> >> > >> > change above
<br>>> >> > >> >
<br>>> >> > >> > Cheers
<br>>> >> > >> > John
<br>>> >> > >> >
<br>>> >> > >> > ______________________________<wbr>__
<br>>> >> > >> > > Date: Mon, 30 Jul 2012 03:37:07 -0700
<br>>> >> > >> > > From:
<br>>> >> > >> > > To:
<br>>> >> > >> > > <a>mojol...@googlegroups.com</a><<wbr>mailto:<a>mojol...@googlegroups.<wbr>com</a>>
<br>>> >> > >>
<br>>> >> > >> > > Subject: Re: [Mojolicious] Authenticating Routes
<br>>> >> > >> > >
<br>>> >> > >> > > Thanks David for the info. Following is the code inside check:
<br>>> >> > >> > >
<br>>> >> > >> > > sub check {
<br>>> >> > >> > > my $self = shift;
<br>>> >> > >> > > return 0 unless($self->is_user_<wbr>authenticated);
<br>>> >> > >> > > return 1;
<br>>> >> > >> > > }
<br>>> >> > >> > >
<br>>> >> > >> > > On Monday, July 30, 2012 1:26:51 PM UTC+5:30, David Oswald
<br>>> >> > >> > > wrote:
<br>>> >> > >> > > > 'main', Main::check, main::check, Main::check,
<br>>> >> > >> > > > main::check code (pay attention to capitalization).
<br>>> >> > >> > >
<br>>> >> > >> > > You see, even after talking about it, I still am getting it
<br>>> >> > >> > > mixed
<br>>> >> > >> > > up.
<br>>> >> > >> > > 'main' vs 'Main'. ...that controller name is begging to be
<br>>> >> > >> > > changed to
<br>>> >> > >> > > something that doesn't resemble Perl's default package. ;)
<br>>> >> > >> > >
<br>>> >> > >> > >
<br>>> >> > >> > > --
<br>>> >> > >> > >
<br>>> >> > >> > > David Oswald
<br>>> >> > >> > >
<br>>> >> > >> > >
<br>>> >> > >> > > --
<br>>> >> > >> > > You received this message because you are subscribed to the
<br>>> >> > >> > > Google
<br>>> >> > >> > > Groups "Mojolicious" group.
<br>>> >> > >> > > To view this discussion on the web visit
<br>>> >> > >> > > <a href="https://groups.google.com/d/msg/mojolicious/-/_uy0fIj3haIJ" target="_blank">https://groups.google.com/d/<wbr>msg/mojolicious/-/_uy0fIj3haIJ</a><wbr>.
<br>>> >> > >> > > To post to this group, send email to
<br>>> >> > >> > <a>mojol...@googlegroups.com</a><<wbr>mailto:<a>mojol...@googlegroups.<wbr>com</a>>.
<br>>> >> > >> > > To unsubscribe from this group, send email to
<br>>> >> > >> > >
<br>>> >> > >> > <a>mojolicious...@googlegroups.<wbr>com</a><mailto:
<br>>> >> > >> <a>mojolicious%...@googlegroups.<wbr>com</a>>.
<br>>> >> > >> > > For more options, visit this group at
<br>>> >> > >> > > <a href="http://groups.google.com/group/mojolicious?hl=en" target="_blank">http://groups.google.com/<wbr>group/mojolicious?hl=en</a>.
<br>>> >> > >> >
<br>>> >> > >> > --
<br>>> >> > >> > You received this message because you are subscribed to the
<br>>> >> > >> > Google
<br>>> >> > >> > Groups "Mojolicious" group.
<br>>> >> > >> > To view this discussion on the web visit
<br>>> >> > >> > <a href="https://groups.google.com/d/msg/mojolicious/-/AnH1vfcVzzoJ" target="_blank">https://groups.google.com/d/<wbr>msg/mojolicious/-/AnH1vfcVzzoJ</a><wbr>.
<br>>> >> > >> > To post to this group, send email to <a>mojol...@googlegroups.com</a>.
<br>>> >> > >> > To unsubscribe from this group, send email to
<br>>> >> > >> > <a>mojolicious...@googlegroups.<wbr>com</a>.
<br>>> >> > >> > For more options, visit this group at
<br>>> >> > >> > <a href="http://groups.google.com/group/mojolicious?hl=en" target="_blank">http://groups.google.com/<wbr>group/mojolicious?hl=en</a>.
<br>>> >> > >>
<br>>> >> > >
<br>>> >> > >
<br>>> >> >
<br>>> >> >
<br>>> >
<br>>> > --
<br>>> > You received this message because you are subscribed to the Google
<br>>> > Groups
<br>>> > "Mojolicious" group.
<br>>> > To view this discussion on the web visit
<br>>> > <a href="https://groups.google.com/d/msg/mojolicious/-/y09M4gItKSEJ" target="_blank">https://groups.google.com/d/<wbr>msg/mojolicious/-/y09M4gItKSEJ</a><wbr>.
<br>>> >
<br>>> > To post to this group, send email to <a>mojol...@googlegroups.com</a>.
<br>>> > To unsubscribe from this group, send email to
<br>>> > <a>mojolicious...@googlegroups.<wbr>com</a>.
<br>>> > For more options, visit this group at
<br>>> > <a href="http://groups.google.com/group/mojolicious?hl=en" target="_blank">http://groups.google.com/<wbr>group/mojolicious?hl=en</a>.
<br>>
<br>> --
<br>> You received this message because you are subscribed to the Google Groups
<br>> "Mojolicious" group.
<br>> To view this discussion on the web visit
<br>> <a href="https://groups.google.com/d/msg/mojolicious/-/LiM2MGKGwDQJ" target="_blank">https://groups.google.com/d/<wbr>msg/mojolicious/-/LiM2MGKGwDQJ</a><wbr>.
<br>>
<br>> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4dht-K1RyacJ">mojol...@googlegroups.com</a>.
<br>> To unsubscribe from this group, send email to
<br>> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="4dht-K1RyacJ">mojolicious...@<wbr>googlegroups.com</a>.
<br>> For more options, visit this group at
<br>> <a href="http://groups.google.com/group/mojolicious?hl=en" target="_blank">http://groups.google.com/<wbr>group/mojolicious?hl=en</a>.
<br></blockquote></div>
------=_Part_336_15766791.1349417958202--
------=_Part_335_7431746.1349417958202--