<div dir="ltr"><div><div><div><div><div>Hi everyone<br><br>I've reverted my app mentioned in my previous post from Dancer2 back to Dancer 1.3111.<br><br></div>This time, an error is shown, but I have no clue what the problem is.<br>
<br>[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<br>
<br>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.<br>
<br></div><div>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?<br><br></div><div>Any pointers would be appreciated. Info follows.<br>
</div><div><br>config.yaml:<br><br>session: "memcached"<br>memcached_servers: "/srv/web/app/sock/sessions.sock"<br></div><div>session_timeout: 10<br></div><div><br></div>running the app as the same user owning the socket above.<br>
<br></div>./bin/<a href="http://app.pl">app.pl</a><br><br></div>==== <a href="http://app.pl">app.pl</a> ====<br><br>#!/usr/bin/env perl<br>use Dancer;<br>use app;<br>start;<br><br></div>==== lib/<a href="http://app.pm">app.pm</a> ====<br>
<br><div><div><div>package app;<br>use Dancer ':syntax';<br>use Dancer::Session::Memcached;<br>use Authen::Simple::Passwd;<br><br>our $VERSION = '0.2';<br><br>hook 'before' => sub {<br> if (request->path_info !~ m{^/app/log}) {<br>
# match login and logout<br> if (session('user') && session('time')) {<br> my $time_now = time;<br> if ($time_now - session('time') < config->{'session_timeout'}) {<br>
session 'time' => $time_now;<br> #context->session 'time' => $time_now;<br> }<br> else {<br> return redirect '/app/logout?msg=session_expired&path=' . request->path_info;<br>
}<br> }<br> else {<br> return redirect '/app/login';<br> }<br> }<br>};<br><br>get '/app/login' => sub {<br><br> my $hostname = request->{'host'};<br> my $msg = 'please login';<br>
if (exists params->{'msg'}) {<br> $msg = params->{'msg'};<br> $msg =~ s/_/ /g;<br> }<br> my $path = '/app/dashboard';<br> if (exists params->{'path'}) {<br> $path = params->{'path'};<br>
}<br> template '<a href="http://login.tt">login.tt</a>', { hostname => $hostname, title => 'login', path => $path, message => $msg };<br><br>post '/app/login' => sub {<br><br> # Validate web<nm> username and password against /etc/passwd<br>
# TODO: use RESTful API to query <a href="http://api.zootzone.com">api.zootzone.com</a><br> if (params->{'pass'} ne '') {<br> my $passwd = Authen::Simple::Passwd->new( path => config->{'passwords'} );<br>
if ($passwd->authenticate(params->{'user'}, params->{'pass'})) {<br> session 'user' => params->{'user'};<br> session 'time' => time;<br> if (params->{'path'}) {<br>
return redirect params->{'path'};<br> }<br> else {<br> return redirect '/app/dashboard';<br> }<br> }<br> else {<br> return redirect '/app/login?msg=authentication_failed';<br>
}<br> } else {<br> return redirect '/app/login?msg=invalid_credentials';<br> }<br>};<br><br></div><div>other routes ....<br></div></div></div></div>