walkingthecow has asked for the wisdom of the Perl Monks concerning the following question:
#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange issue with Mojolicious
by Anonymous Monk on May 01, 2013 at 11:34 UTC | |
by walkingthecow (Friar) on May 01, 2013 at 11:39 UTC | |
by Anonymous Monk on May 01, 2013 at 11:54 UTC | |
by walkingthecow (Friar) on May 02, 2013 at 11:02 UTC | |
by Pizentios (Scribe) on May 01, 2013 at 14:15 UTC |