[dancer-users] Session request crashed (using Dancer::Session::Memcached)
Dale Gallagher
dale.gallagher at gmail.com
Wed Apr 10 17:57:04 BST 2013
Hi everyone
I've reverted my app mentioned in my previous post from Dancer2 back to
Dancer 1.3111.
This time, an error is shown, but I have no clue what the problem is.
[hit #2]request to GET /panel/login crashed: Can't call method "id" without
a package or object reference at
/usr/lib/perl5/site_perl/5.12.3/Dancer/Session.pm line 36, <DATA> line 16.
in /usr/lib/perl5/site_perl/5.12.3/Dancer/Handler.pm l. 98
This app works without error using the Simple, YAML and JSON session
engines, but fails with Memcached. I know the Memcached instance is working
as per my previous post, as accessing it with a regular perl script using
Cache::Memcached works.
It seems either something's amiss with my Memcached instance, which the
test script doesn't pick up, or there's a bug in Dancer::Session::Memcached?
Any pointers would be appreciated. Info follows.
config.yaml:
session: "memcached"
memcached_servers: "/srv/web/app/sock/sessions.sock"
session_timeout: 10
running the app as the same user owning the socket above.
./bin/app.pl
==== app.pl ====
#!/usr/bin/env perl
use Dancer;
use app;
start;
==== lib/app.pm ====
package app;
use Dancer ':syntax';
use Dancer::Session::Memcached;
use Authen::Simple::Passwd;
our $VERSION = '0.2';
hook 'before' => sub {
if (request->path_info !~ m{^/app/log}) {
# match login and logout
if (session('user') && session('time')) {
my $time_now = time;
if ($time_now - session('time') < config->{'session_timeout'}) {
session 'time' => $time_now;
#context->session 'time' => $time_now;
}
else {
return redirect '/app/logout?msg=session_expired&path=' .
request->path_info;
}
}
else {
return redirect '/app/login';
}
}
};
get '/app/login' => sub {
my $hostname = request->{'host'};
my $msg = 'please login';
if (exists params->{'msg'}) {
$msg = params->{'msg'};
$msg =~ s/_/ /g;
}
my $path = '/app/dashboard';
if (exists params->{'path'}) {
$path = params->{'path'};
}
template 'login.tt', { hostname => $hostname, title => 'login', path =>
$path, message => $msg };
post '/app/login' => sub {
# Validate web<nm> username and password against /etc/passwd
# TODO: use RESTful API to query api.zootzone.com
if (params->{'pass'} ne '') {
my $passwd = Authen::Simple::Passwd->new( path => config->{'passwords'}
);
if ($passwd->authenticate(params->{'user'}, params->{'pass'})) {
session 'user' => params->{'user'};
session 'time' => time;
if (params->{'path'}) {
return redirect params->{'path'};
}
else {
return redirect '/app/dashboard';
}
}
else {
return redirect '/app/login?msg=authentication_failed';
}
} else {
return redirect '/app/login?msg=invalid_credentials';
}
};
other routes ....
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130410/6b61442d/attachment.htm>
More information about the dancer-users
mailing list