Couple probelms with the "growing" tut form the Docs.

63 views
Skip to first unread message

Ray Sleeper

unread,
Aug 2, 2014, 7:42:56 PM8/2/14
to mojol...@googlegroups.com
I'm getting an error for the 'check password' part of the tut:
Can't locate object method "check" via package "Mojolicious::Lite" at myapp.pl

I get the same for 'method secret' part as well
Here are the offending codes:

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.
Any insight would be appreciated.

btw I am brand new to Mojolicious, but I have some experience in perl.




sri

unread,
Aug 2, 2014, 7:58:23 PM8/2/14
to mojol...@googlegroups.com
I can post all the code, but it's exactly the same as in the tutorial.

If it was, it would work.

--
sebastian 

Ray Sleeper

unread,
Aug 2, 2014, 8:02:35 PM8/2/14
to mojol...@googlegroups.com
Thanks for the insight, that was really helpful.

A more constructive reply would have been to simply ask me to post all my code.
Is that in fact what you are trying to say?

sri

unread,
Aug 2, 2014, 8:09:22 PM8/2/14
to mojol...@googlegroups.com
Thanks for the insight, that was really helpful.

Please be nice, passive-aggressive beheavior is not welcome here.

--
sebastian 

Ray Sleeper

unread,
Aug 2, 2014, 8:15:26 PM8/2/14
to mojol...@googlegroups.com
Here is the full code:

#!/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>

       

       
       
       

rocko

unread,
Aug 2, 2014, 11:35:10 PM8/2/14
to mojol...@googlegroups.com
BTW, I do have a 'check' sub in the 'MyUsers.pm' file.
Just in case anyone was wondering.

On 08/02/2014 05:15 PM, Ray Sleeper wrote:
--
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.

Dotan Dimet

unread,
Aug 3, 2014, 3:12:37 AM8/3/14
to mojol...@googlegroups.com
Shoudn't that be MyUsers->new ? You've got MyUsers=>new
Replace => with -> and you'll hopefully have a MyUsers object.
--
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.


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

acidblue

unread,
Aug 3, 2014, 1:35:02 PM8/3/14
to mojol...@googlegroups.com
AHA!
Thanks Dotan, that clears the "check" error, but i'm still getting the "secrete not found in Mojo::etc " error.

Per Carlson

unread,
Aug 3, 2014, 2:13:44 PM8/3/14
to mojolicious
On 3 August 2014 19:35, acidblue <sunbl...@gmail.com> wrote:
AHA!
Thanks Dotan, that clears the "check" error, but i'm still getting the "secrete not found in Mojo::etc " error.

​Are you sure you are using Mojolicious version 4.63 or newer (see: https://github.com/kraih/mojo/blob/master/Changes#L398)?

​What does "mojo version" tell you?​

rocko

unread,
Aug 3, 2014, 2:22:28 PM8/3/14
to mojol...@googlegroups.com
mojo version returns:

  Perl        (v5.14.2, linux)
  Mojolicious (4.19, Top Hat)

That could be the problem, I"ll upgrade and report back, but give me a sec I gotta go grab some lunch ;)
--
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.

rocko

unread,
Aug 3, 2014, 2:57:11 PM8/3/14
to mojol...@googlegroups.com
Yep, that was it.
Upgraded to 5.25.
Had no idea I was running an older Mojo

Thanks for the help




On 08/03/2014 11:13 AM, Per Carlson wrote:
--
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.
Reply all
Reply to author
Forward
0 new messages