| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | =head1 NAME | ||
| 5 | |||
| 6 | Jifty::Plugin::Authentication::Password::Action::ResetPassword - Confirm and reset a lost password | ||
| 7 | |||
| 8 | =head1 DESCRIPTION | ||
| 9 | |||
| 10 | This is the action run by the link in a user's email to confirm that their email | ||
| 11 | address is really theirs, when claiming that they lost their password. | ||
| 12 | |||
| 13 | |||
| 14 | =cut | ||
| 15 | |||
| 16 | package Jifty::Plugin::Authentication::Password::Action::ResetLostPassword; | ||
| 17 | use base qw/Jifty::Action/; | ||
| 18 | |||
| 19 | =head2 arguments | ||
| 20 | |||
| 21 | ConfirmEmail has the following fields: address, code, password, and password_confirm. | ||
| 22 | Note that it can get the first two from the confirm dhandler. | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | sub arguments { | ||
| 27 | return ( | ||
| 28 | { | ||
| 29 | password => { | ||
| 30 | type => 'password', | ||
| 31 | sticky => 0, | ||
| 32 | label => _('Password') | ||
| 33 | }, | ||
| 34 | password_confirm => { | ||
| 35 | type => 'password', | ||
| 36 | sticky => 0, | ||
| 37 | label => _('type your password again') | ||
| 38 | }, | ||
| 39 | } | ||
| 40 | ); | ||
| 41 | } | ||
| 42 | |||
| 43 | =head2 take_action | ||
| 44 | |||
| 45 | Resets the password. | ||
| 46 | |||
| 47 | =cut | ||
| 48 | |||
| 49 | sub take_action { | ||
| 50 | my $self = shift; | ||
| 51 | my $u = Jifty->web->current_user->user_object->as_superuser; | ||
| 52 | |||
| 53 | unless ($u) { | ||
| 54 | $self->result->error( | ||
| 55 | join( ' ', | ||
| 56 | _("You don't exist."), | ||
| 57 | _("I'm not sure how this happened."), | ||
| 58 | _("Really, really sorry."), | ||
| 59 | _("Please email us!") ) | ||
| 60 | ); | ||
| 61 | } | ||
| 62 | |||
| 63 | my $pass = $self->argument_value('password'); | ||
| 64 | my $pass_c = $self->argument_value('password_confirm'); | ||
| 65 | |||
| 66 | # Trying to set a password (i.e., submitted the form) | ||
| 67 | unless (defined $pass and defined $pass_c and length $pass and $pass eq $pass_c ) { | ||
| 68 | $self->result->error( _("It looks like you didn't enter the same password into both boxes. Give it another shot?") | ||
| 69 | ); | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | |||
| 73 | unless ( $u->set_password($pass) ) { | ||
| 74 | $self->result->error(_("There was an error setting your password.")); | ||
| 75 | return; | ||
| 76 | } | ||
| 77 | |||
| 78 | $u->set_email_confirmed('1'); | ||
| 79 | # Log in! | ||
| 80 | $self->result->message(_("Your password has been reset. Welcome back.")); | ||
| 81 | my $CurrentUser = Jifty->app_class('CurrentUser'); | ||
| 82 | Jifty->web->current_user( $CurrentUser->new( id => $u->id ) ); | ||
| 83 | return 1; | ||
| 84 | |||
| 85 | } | ||
| 86 | |||
| 87 | 1; |