iam looking for authentification in Mojolicious. I have 2 pages momcorp1 and momcorp2, But i cant pas between over pages, someone know how do this.
Iam reaading about "under", but i dont undertah how do this.
The other form do this is use -Mojolicious::Plugin::Authentication - but is more dificult.
This is the code, when 1 click link to momcorp 2, show error.
#!/usr/bin/env perl
use Mojolicious::Lite;
helper auth => sub {
my $self = shift;
return 1 if
$self->param('username') eq 'user1' and
$self->param('password') eq 'user1';
};
get '/login'=> sub { shift->render('login') };
under sub {
my $self = shift;
return 1 if $self->auth;
$self->render(text => 'denied');
return;
};
post 'momcorp' => sub { shift->render(template => 'momcorp1') };
post '/momcorp/carol' => sub { shift->render(template => 'momcorp2')
};
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
@@ momcorp1.html.ep
%= t h1 => 'momcorp1'
<a href="/momcorp/carol">Link to 2</a>
@@ momcorp2.html.ep
%= t h1 => 'momcorp2'
<a href="/momcorp">Link to 1</a>
Here's an example of what you want