Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #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

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

  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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (8)
    As of 2015-11-30 13:00 GMT
    Find Nodes?
      Voting Booth?

      What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

      Results (770 votes), past polls