![]() |
![]()
| ![]() |
![]()
NAMECatalyst::Controller::RequestToken - Handling transaction tokens across formsSYNOPSISrequires Catalyst::Plugin::Session module, in your application class:use Catalyst qw/ Session Session::State::Cookie Session::Store::FastMmap FillInForm /; in your controller class: use base qw(Catalyst::Controller::RequestToken); sub form :Local { my ($self, $c) = @_; $c->stash( template => 'form.tt' ); } sub confirm :Local :CreateToken { my ($self, $c) = @_; $c->stash( template => 'confirm.tt' ); } sub complete :Local :ValidateToken { my ($self, $c) = @_; if ($self->valid_token($c)) { $c->response->body('complete.'); } eles { $c->response->body('invalid operation.'); } } form.tt <html> <body> <form action="confirm" method="post"> <input type="submit" name="submit" value="confirm"/> </form> </body> </html> confirm.tt <html> <body> <form action="complete" method="post"> <input type="hidden" name="_token" values="[% c.req.param('_token') %]"/> <input type="submit" name="submit" value="complete"/> </form> </body> </html> DESCRIPTIONThis controller enables to enforce a single transaction across multiple forms. Using a token, you can prevent duplicate submits and protect your app from CSRF atacks.This module REQUIRES Catalyst::Plugin::Session to store server side token. ATTRIBUTES
METHODSAll methods must be passed the request context as their first parameter.
CONFIGRATIONin your application class:__PACKAGE__->config('Controller::TokenBasedMyController' => { session_name => '_token', request_name => '_token', });
SEE ALSO
AUTHORHideo Kimura "<<hide<at>hide-k.net>>"COPYRIGHTThis program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.The full text of the license can be found in the LICENSE file included with this module.
|