params for post route not working
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'; } }; ---- 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
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@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
-- Joel Roth
On Sun, Feb 19, 2012 at 04:01:36PM -1000, Joel Roth wrote:
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' }
Thanks Joel. That doesn't work for me, but there is a 500 involved, so that may be a separate issue from getting Dancer to grok params, presuming validation_succeeds() is a Dancer method? GJ
On Mon, Feb 20, 2012 at 06:26:45AM +0000, GJ wrote:
On Sun, Feb 19, 2012 at 04:01:36PM -1000, Joel Roth wrote:
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' }
Thanks Joel. That doesn't work for me, but there is a 500 involved, so that may be a separate issue from getting Dancer to grok params, presuming validation_succeeds() is a Dancer method?
No, it's just a stand-in for whatever authentication you use, i.e.
if (params->{user} eq 'bob' && params->{pass} eq 'a') {
-- Joel Roth
On Sun, 19 Feb 2012 23:20:48 +0000 GJ <gj@freeshell.org> 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'; } }; ----
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.
Interesting. Can you dump the request object returned by the 'request' keyword so we can see what Dancer got? -- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github
Hello, I think this problem can be related with this my pull request: https://github.com/sukria/Dancer/pull/702 This pull request is not realized but from this bug the Dancer cannot get HTTP Headers under PSGI invocation (for example under Starman). A POST requests use a HTTP Headers for param getting and if http headers are empty request object can return undefined POST parameters 2012/2/20 David Precious <davidp@preshweb.co.uk>:
On Sun, 19 Feb 2012 23:20:48 +0000 GJ <gj@freeshell.org> 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'; } }; ----
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.
Interesting. Can you dump the request object returned by the 'request' keyword so we can see what Dancer got?
-- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github _______________________________________________ Dancer-users mailing list Dancer-users@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
On Mon, Feb 20, 2012 at 10:54:04AM +0000, David Precious 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'; } }; ----
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.
Interesting. Can you dump the request object returned by the 'request' keyword so we can see what Dancer got?
I accidentally replied to earlier to David only instead of the list. As I said earlier, this is the result of dumping the request object whilst running under Apache -- my intended production environment. BTW, you may see some non-Dancer cookie stuff in there; that is because I'm porting my authentication scheme from the old cgi setup in stages. I don't think it is necessarily causally related to the emptiness because POSTed params don't work at all right now. Regards, GJ ---- $VAR1 = bless( { '_read_position' => 0, 'content_length' => '27', 'connection' => 'keep-alive', 'headers' => bless( { 'user-agent' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1', 'connection' => 'keep-alive', 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept-language' => 'en-us,en;q=0.5', 'cookie' => 'session=5aa3a19de3fdd444d66a0ff1a799cc721a0d72a0; user_name=admin; dancer.session=empty', 'accept-encoding' => 'gzip, deflate', 'content-length' => '27', 'host' => 'localhost', 'accept-charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'content-type' => 'application/x-www-form-urlencoded', 'referer' => 'http://localhost/login' }, 'HTTP::Headers' ), '_http_body' => bless( { 'content_length' => '27', 'tmpdir' => '/tmp', 'buffer' => '', 'state' => 'buffering', 'chunk_buffer' => '', 'body' => undef, 'content_type' => 'application/x-www-form-urlencoded', 'length' => 0, 'chunked' => '', 'upload' => {}, 'param_order' => [], 'param' => {}, 'cleanup' => 1 }, 'HTTP::Body::UrlEncoded' ), '_route_pattern' => '/login', 'accept_encoding' => 'gzip, deflate', '_route_params' => {}, 'is_forward' => 0, 'uploads' => {}, '_body_params' => $VAR1->{'_http_body'}{'param'}, 'body' => '', 'accept_charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'method' => 'POST', 'id' => 1, 'referer' => 'http://localhost/login', 'accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'accept_type' => undef, 'env' => { 'psgi.multiprocess' => 1, 'SCRIPT_NAME' => '', 'PATH_INFO' => '/login', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'REQUEST_METHOD' => 'POST', 'psgi.multithread' => 0, 'SCRIPT_FILENAME' => '/home/gj/My-App/public/dispatch.cgi', 'SERVER_SOFTWARE' => 'Apache/2.2.14 (Ubuntu)', 'PLACK_ENV' => 'development', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1', 'REMOTE_PORT' => '51328', 'QUERY_STRING' => '', 'SERVER_SIGNATURE' => '<address>Apache/2.2.14 (Ubuntu) Server at localhost Port 80</address> ', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'DANCER_APPDIR' => '/home/gj/My-App/bin/..', 'psgi.streaming' => 1, 'PATH' => '/usr/local/bin:/usr/bin:/bin', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'psgi.version' => [ 1, 1 ], 'SCRIPT_URL' => '/login', 'DOCUMENT_ROOT' => '/home/gj/My-App/public', 'psgi.run_once' => 1, 'PATH_TRANSLATED' => '/home/gj/My-App/public/dispatch.cgi/login', 'SERVER_NAME' => 'localhost', 'HTTP_REFERER' => 'http://localhost/login', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'SERVER_ADMIN' => 'you@example.com', 'HTTP_CONNECTION' => 'keep-alive', 'SCRIPT_URI' => 'http://localhost/login', 'CONTENT_LENGTH' => '27', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'SERVER_PORT' => '80', 'HTTP_COOKIE' => 'session=5aa3a19de3fdd444d66a0ff1a799cc721a0d72a0; user_name=admin; dancer.session=empty', 'REMOTE_ADDR' => '127.0.0.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'psgi.errors' => *::STDERR, 'REQUEST_URI' => '/login', 'psgi.nonblocking' => 1, 'SERVER_ADDR' => '127.0.0.1', 'psgi.url_scheme' => 'http', 'HTTP_HOST' => 'localhost', 'psgi.input' => *::STDIN }, 'user_agent' => 'Mozilla/5.0 (Ubuntu; X11; Linux i686; rv:9.0.1) Gecko/20100101 Firefox/9.0.1', 'x_requested_with' => undef, 'path' => '/login', 'path_info' => '/login', 'accept_language' => 'en-us,en;q=0.5', '_chunk_size' => 4096, '_query_params' => {}, 'host' => 'localhost', 'ajax' => 0, 'params' => {}, 'content_type' => 'application/x-www-form-urlencoded', 'keep_alive' => undef }, 'Dancer::Request' );
participants (4)
-
David Precious -
GJ -
Joel Roth -
Perlover