[Dancer-users] Session cookie and send_file doubt

sawyer x xsawyerx at gmail.com
Mon Feb 28 12:45:23 CET 2011


Hey

Sorry for the long reply.

If you've noticed the last email Alexis wrote, I think it relates to this.
It should be fixed very soon (since this is a very important issue) and I
think that once it's sorted, either your situation will be fixed or much
easier to fix.

Thanks,
Sawyer.

On Tue, Feb 22, 2011 at 10:27 AM, Javier Sanchez <sjllera at gmail.com> wrote:

>
>
> 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
>
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110228/c07c6c44/attachment.htm>


More information about the Dancer-users mailing list