[Dancer-users] Session cookie and send_file doubt

Javier Sanchez sjllera at gmail.com
Tue Feb 22 09:27:22 CET 2011


Hello  !!

im new to dancer adn im really enjoying hwo easy and simple it is, im
actuaally testing some examples on the cookbook and soms
simple functions and encountered a strange behaviour i cannot understand.
Heres the code.


#!/usr/bin/env perl
use Dancer;
use MyApp01;

set port => 9001;

    before sub {

        if (! session('user') && request->path_info !~ m{^/login}) {
            redirect('/login');
        }
    };

    get '/login' => sub {
        # Display a login page; the original URL they requested is available
as
        # vars->{requested_path}, so could be put in a hidden field in the
form
        template 'login', { path => vars->{requested_path} };
    };

  post '/login' => sub {
        # Validate the username and password they supplied
        if (params->{username} eq 'bob' && params->{password} eq 'mierda') {
            session user => params->{user};
            redirect params->{path} || '/';
        } else {
            redirect '/login?failed=1';
        }
    };

  get '/logout' => sub {
     session->destroy;
     set_flash('You are logged out.');
     redirect '/login';
  };

  get '/' => sub {
        if (session('user')) {
            redirect('/login');
        } else {
                send_file '/o.html' ;
        }
  };

  get '/hello/:name/peter' => sub {
        return "Hi there " . params->{name};
  };


Allmos as posted on the dancer cookbook, login redirection works perfect,
except when i request o.html, no matter if i
explicit test if the user is logged, the file is shown on the browser. Its a
simple html form, and when i click on submit im
correctly redirected to /login but why is the first request not blocked ?
Did i miss something on the manual about static files
and session management ?


Thank you
Javi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110222/b7243bc7/attachment.htm>


More information about the Dancer-users mailing list