Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am following the webcasts and really enjoying them. However, I have hit a point of frustration. When I run the code that is presented in episode 3 (unless my eyes deceive me, it is exactly as presented in the video), I do not get the same results. When the presenter enters the wrong username and password, he gets "denied," while the correct username and password yeilds "Welcome to Momcorp!" For me, no matter what I enter with the code below, I get "Welcome to Momcorp!" Am I missing something here?
#!/usr/bin/env perl use Mojolicious::Lite; # Helpers = in app extensions helper auth => sub { my $self = shift; return 1 if $self->param('username') eq 'bender' and $self->param('password') eq 'rodriguez'; }; get '/login' => sub { shift->render('login') }; post '/momcorp' => sub { my $self = shift; $self->render(text => 'denied') if !$self->auth; $self->render(text => 'Welcome to Momcorp!'); }; post '/momcorp/carol' => sub { my $self=shift; $self->render(text => 'denied') if !$self->auth; $self->render(text => 'Welcome, Carol!'); }; app->start; __DATA__ @@ login.html.ep <h1>Login</h1> <form method="post" action="/momcorp"> Username: <input type="text" name="username" /> Password: <input type="text" name="password" /> <input type="submit" value="Log In" /> </form>

Version Information

CORE
  Perl        (v5.16.3, linux)
  Mojolicious (3.97, Rainbow)

OPTIONAL
  EV 4.0+               (not installed)
  IO::Socket::IP 0.16+  (not installed)
  IO::Socket::SSL 1.75+ (not installed)

This version is up to date, have fun!

Later in the video we modify the code to use under and tag helpers. Oddly, this code does work:
#!/usr/bin/env perl use Mojolicious::Lite; # Helpers = in app extensions helper auth => sub { my $self = shift; return 1 if $self->param('username') eq 'bender' and $self->param('password') eq 'rodriguez'; }; get '/login' => sub { shift->render('login') }; # Under: protects actions listed underneath the under # Modify behavior of any action under... # if returns true actions under can be matched # false, they are inaccessible # removes duplicate code :) under sub { my $self = shift; return 1 if $self->auth; $self->render(text => 'denied'); return; }; post '/momcorp' => sub { shift->render(text => 'Welcome to Momco +rp!') }; post '/momcorp/carol' => sub { shift->render(text => 'Welcome, Carol!' +) }; app->start; __DATA__ @@ login.html.ep %= t h1 => 'Login' %= form_for '/momcorp' => (method => 'post') => begin Username: <%= text_field 'username' %> Password: <%= text_field 'password' %> %= submit_button 'Log In' %= end

In reply to Strange issue with Mojolicious by walkingthecow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 11:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found