app->secrets(['Mojolicious rocks']);
return $c->render unless $c->users->check($user, $pass);
I can post all the code, but it's exactly the same as in the tutorial.
Thanks for the insight, that was really helpful.
#!/usr/bin/env perl
use Mojolicious::Lite;
use lib 'lib';
use MyUsers;
app->secrets(['Mojolicious rocks']);
# Helper to lazy initialize and store our model object
helper users => sub { state $users = MyUsers=>new };
any '/' => sub {
my $c = shift;
# Querry parameters
my $user = $c->param('user') || '';
my $pass = $c->param('pass') || '';
# check password
return $c->render unless $c->users->check($user, $pass);
# Store username in session
$c->session(user => $user);
$c->flash(message => 'Thanks for logging in.');
# redirect to protected page with 302 respons
$c->redirect_to('protected');
} => 'index';
group {
under sub {
my $c = shift;
# redirect to main with 302 response if not logged in
return 1 if $c->session('user');
$c->redirect_to('index');
return undef;
};
#protected page
get '/protected';
};
#Logout
get '/logout' => sub {
my $c = shift;
$c->session(expires => 1);
#redirect to main with 302
$c->redirect_to('index');
};
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
%= form_for index => begin
% if (param 'user' ) {
<b>Wrong name or password, plea try againm.</b><b>
% }
Name:<br>
%= text_field 'user'
<br>Password:<br>
%= submit_button 'Login'
% end
@@ protected.html.ep
% layout 'default';
% if (my $msg = flash 'message' ) {
<b><%= $msg %></b><br>
% }
Welcome <%= session 'user' %>.<br>
%= link_to Logout => 'logout'
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title>Login Manager</title></head>
<body><%= content %></body>
</html>
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WXVFOTEnghc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
MyUsers->new ? You've got
MyUsers=>new--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
AHA!
Thanks Dotan, that clears the "check" error, but i'm still getting the "secrete not found in Mojo::etc " error.
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WXVFOTEnghc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/WXVFOTEnghc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.