| 1 | package HTML::FormHandler::TraitFor::Captcha; | ||
| 2 | # ABSTRACT: generate and validate captchas | ||
| 3 | $HTML::FormHandler::TraitFor::Captcha::VERSION = '0.410002'; | ||
| 4 | use HTML::FormHandler::Moose::Role; | ||
| 5 | use GD::SecurityImage; | ||
| 6 | use HTTP::Date; | ||
| 7 | |||
| 8 | requires('ctx'); | ||
| 9 | |||
| 10 | has_field 'captcha' => ( type => 'Captcha', label => 'Verification' ); | ||
| 11 | |||
| 12 | |||
| 13 | sub get_captcha { | ||
| 14 | my $self = shift; | ||
| 15 | return unless $self->ctx; | ||
| 16 | my $captcha; | ||
| 17 | $captcha = $self->ctx->session->{captcha}; | ||
| 18 | return $captcha; | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | sub set_captcha { | ||
| 23 | my ( $self, $captcha ) = @_; | ||
| 24 | return unless $self->ctx; | ||
| 25 | $self->ctx->session( captcha => $captcha ); | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | sub captcha_image_url { | ||
| 30 | return '/captcha/image'; | ||
| 31 | } | ||
| 32 | |||
| 33 | use namespace::autoclean; | ||
| 34 | 1; | ||
| 35 | |||
| 36 | __END__ |