Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Why is mojolicious "routing to a callback" ?

by pcouderc (Monk)
on Nov 25, 2015 at 09:27 UTC ( [id://1148590]=perlquestion: print w/replies, xml ) Need Help??

pcouderc has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am trying to authenticate and I success :
sub startup { my $self = shift; my $r = $self->routes; $r->get('/:layout')->to('login#nolog'); $r->get('/:layout/logout')->to('login#logout'); my $auth = $r->under( sub { return defined($self->session('userid' +)) } ); $auth->get('/:layout/menu')->to('login#menu'); $r->any('/:layout/:dummy')->to('login#nolog');}
I authenticate in Login.pm sub nolog, I define userid and I redirect to "upsmichel/menu", I expect "login/menu.html.ep" to be rendered but instead I am routed to a callback ?
why ? What do I miss ?
Thanks
PC
Wed Nov 25 10:03:48 2015] [debug] GET "/upsmichel/nolog". [Wed Nov 25 10:03:48 2015] [debug] Routing to controller "Myapp::Contr +oller::Login" and action "nolog". [Wed Nov 25 10:03:48 2015] [debug] Rendering cached template "login/no +log.html.ep". [Wed Nov 25 10:03:48 2015] [debug] Rendering cached template "layouts/ +upsmichel.html.ep". [Wed Nov 25 10:03:48 2015] [debug] 200 OK (0.061906s, 16.154/s). [Wed Nov 25 10:04:02 2015] [debug] POST "/upsmichel/nolog". [Wed Nov 25 10:04:02 2015] [debug] Routing to controller "Myapp::Contr +oller::Login" and action "nolog". [Wed Nov 25 10:04:02 2015] [debug] 302 Found (0.031328s, 31.920/s). [Wed Nov 25 10:04:02 2015] [debug] GET "/upsmichel/menu". [Wed Nov 25 10:04:02 2015] [debug] Routing to a callback. [Wed Nov 25 10:04:02 2015] [debug] Nothing has been rendered, expectin +g delayed response.

Replies are listed 'Best First'.
Re: Why is mojolicious "routing to a callback" ?
by Corion (Patriarch) on Nov 25, 2015 at 09:29 UTC

    Can you maybe show us a small, self-contained example that we can use to replicate your problem? Something that has a minimal login/menu.html.ep and the minimal code to reproduce?

      Mmm, minimum, it is trivial with : Login.pm
      package Myapp::Controller::Login; use Mojo::Base 'Mojolicious::Controller'; sub nolog { my $c = shift; $c->session(userid => 1); $c->redirect_to('menu'); } 1;
      and nolog.htlm.rp :
      %= form_for nolog => (method => 'POST') => begin <p> % if (param 'user') { <b>Erreur dans le mot de passe ou le nom d'utilisateur. Veuillez r +éessayer</b><br> % } Utilisateur :<br> %= text_field 'user' <br>Mot de passe :<br> %= password_field 'pass' <br> %= submit_button 'Login' </p> % end
      and login.htlm.ep :
      <p> ... </p>
      Self contained, I do not know how to do (I am not with Mojolicious::Lite)..
        Does Class "MyApp::Controller::Login" is not a controller mean anything to you?
Re: Why is mojolicious "routing to a callback" ?
by ctilmes (Vicar) on Nov 25, 2015 at 19:24 UTC

    "Routing to a callback" means calling a "sub { ... }" instead of a to('somecontroller#someaction'). If you give it a name it will print the name instead of just "a callback". (conversely, you can embed any of them with a sub{} callback instead of a name and it will say just "Routing to a callback" instead of "Routing to controller/action".

    It is probably calling your $r->under() sub and failing.
      Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1148590]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found