| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Jifty::Plugin::Authentication::Password::Action::SendAccountConfirmation - send confirmation for an email | ||
| 7 | |||
| 8 | =cut | ||
| 9 | |||
| 10 | package Jifty::Plugin::Authentication::Password::Action::SendAccountConfirmation; | ||
| 11 | use base qw/Jifty::Action/; | ||
| 12 | |||
| 13 | __PACKAGE__->mk_accessors(qw(user_object)); | ||
| 14 | |||
| 15 | =head2 arguments | ||
| 16 | |||
| 17 | The field for C<ResendConfirmation> is: | ||
| 18 | |||
| 19 | =over 4 | ||
| 20 | |||
| 21 | =item address: the email address | ||
| 22 | |||
| 23 | =back | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | sub arguments { | ||
| 28 | return ( | ||
| 29 | { | ||
| 30 | address => { | ||
| 31 | label => _('email address'), | ||
| 32 | mandatory => 1, | ||
| 33 | default_value => "", | ||
| 34 | }, | ||
| 35 | } | ||
| 36 | ); | ||
| 37 | } | ||
| 38 | |||
| 39 | =head2 setup | ||
| 40 | |||
| 41 | Create an empty user object to work with | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | sub setup { | ||
| 46 | my $self = shift; | ||
| 47 | my $LoginUser = Jifty->app_class('Model', 'User'); | ||
| 48 | my $CurrentUser = Jifty->app_class('CurrentUser'); | ||
| 49 | |||
| 50 | $self->user_object( | ||
| 51 | $LoginUser->new( current_user => $CurrentUser->superuser ) ); | ||
| 52 | } | ||
| 53 | |||
| 54 | =head2 validate_address | ||
| 55 | |||
| 56 | Make sure their email address is an unconfirmed user. | ||
| 57 | |||
| 58 | =cut | ||
| 59 | |||
| 60 | sub validate_address { | ||
| 61 | my $self = shift; | ||
| 62 | my $email = shift; | ||
| 63 | |||
| 64 | my $LoginUser = Jifty->app_class('Model', 'User'); | ||
| 65 | my $CurrentUser = Jifty->app_class('CurrentUser'); | ||
| 66 | |||
| 67 | return $self->validation_error( | ||
| 68 | address => _("That doesn't look like an email address.") ) | ||
| 69 | unless ( $email =~ /\S\@\S/ ); | ||
| 70 | |||
| 71 | $self->user_object( | ||
| 72 | $LoginUser->new( current_user => $CurrentUser->superuser ) ); | ||
| 73 | $self->user_object->load_by_cols( email => $email ); | ||
| 74 | return $self->validation_error( | ||
| 75 | address => _("It doesn't look like there's an account by that name.") ) | ||
| 76 | unless ( $self->user_object->id ); | ||
| 77 | |||
| 78 | return $self->validation_error( | ||
| 79 | address => _("It looks like you're already confirmed.") ) | ||
| 80 | if ( $self->user_object->email_confirmed ); | ||
| 81 | |||
| 82 | return $self->validation_ok('address'); | ||
| 83 | } | ||
| 84 | |||
| 85 | =head2 take_action | ||
| 86 | |||
| 87 | Create a new unconfirmed user and send out a confirmation email. | ||
| 88 | |||
| 89 | =cut | ||
| 90 | |||
| 91 | sub take_action { | ||
| 92 | my $self = shift; | ||
| 93 | Jifty::Plugin::Authentication::Password::Notification::ConfirmAddress->new( to => $self->user_object )->send; | ||
| 94 | return $self->result->message(_("Confirmation resent.")); | ||
| 95 | } | ||
| 96 | |||
| 97 | 1; |