[Dancer-users] params for post route not working

Joel Roth joelz at pobox.com
Mon Feb 20 03:01:36 CET 2012


On Sun, Feb 19, 2012 at 11:20:48PM +0000, GJ wrote:
> Hi all,
> 
> I am using Dancer 1.3092 .  I can't access or use params for post routes, eg
> 
> ----
> post '/login' => sub {
>     # Validate the username and password they supplied
>     if (params->{user} eq 'bob' && params->{pass} eq 'a') {
>         session user => params->{user};
>         redirect params->{path} || '/';
>     } else {
>         redirect '/login?failed=1';
>     }
> };

This code works for me when used with (now-deprecated)
before.

I recall difficulties getting documentated examples
to work as advertised.


post '/login' => sub {
	if ( validation_succeeds() )
    {
        session user => params->{user};
        my $path = session->{requested_path} || '/';
        session requested_path => undef;
        session failed_login => undef;
        redirect $path;

     } 
     else 
     {

		session failed_login => 1;
		redirect '/login'
     }          

HTH,



> ----
> 
> The above example is from the documentation, the result is the `else'
> redirection. I tried my own code also.  params->user is empty, in fact if I
> dump all `params' its empty.  I also tried `$user = param "user"' and every
> other thing I could find in the docs, and it is the same result, nothing.
> 
> Is there something I need to set? My config.yml is as follows:
> 
> ----
> appname: "My::App"
> 
> # The default layout to use for your application (located in
> # views/layouts/main.tt)
> layout: "main"
> 
> # when the charset is set to UTF-8 Dancer will handle for you
> # all the magic of encoding and decoding. You should not care
> # about unicode within your app when this setting is set (recommended).
> charset: "UTF-8"
> 
> #template: "simple"
> template: "html_template"
> engines:
>  HtmlTemplate:
>    loop_context_vars: '1'
>    global_vars: '1'
> 
> session: "cookie"
> session_cookie_key: "xxxx"
> 
> plugins:
>                Database:
>                    driver: 'mysql'
>                    database: 'xxxx'
>                    host: 'localhost'
>                    username: 'xxxx'
>                    password: 'xxxx'
> ----
> 
> Any help would be appreciated.  Regards, 
> GJ
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users

-- 
Joel Roth


More information about the Dancer-users mailing list