Jifty/Plugin/Authentication/Password/Action/SendPasswordReminder.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 43 CC 3 SCAR 16.7
CC
3
Cov
0%
validate_address
12.0
arguments
2.0
setup
2.0
CRAP 5.3
1 use warnings;
2 use strict;
3  
4 =head1 NAME
5  
6 Jifty::Plugin::Authentication::Password::Action::SendPasswordReminder - send a link to reset a password
7  
8 =cut
9  
10 package Jifty::Plugin::Authentication::Password::Action::SendPasswordReminder;
11 use base qw/Jifty::Action/;
12  
13  
14 __PACKAGE__->mk_accessors(qw(user_object));
15  
16 =head2 arguments
17  
18 The field for C<SendLostPasswordReminder> is:
19  
20 =over 4
21  
22 =item address: the email address
23  
24 =back
25  
26 =cut
27  
28 sub arguments {
29 return (
30 {
31 address => {
32 label => _('Email'),
33 mandatory => 1,
34 },
35 }
36 );
37  
38 }
39  
40 =head2 setup
41  
42 Create an empty user object to work with
43  
44 =cut
45  
46 sub setup {
47 my $self = shift;
48 my $LoginUser = Jifty->app_class('Model','User');
49 my $CurrentUser = Jifty->app_class('CurrentUser');
50  
51  
52  
53 # Make a blank user object
54 $self->user_object(
55 $LoginUser->new( current_user => $CurrentUser->superuser ) );
56 }
57  
58 =head2 validate_address
59  
60 Make sure there's actually an account by that name.
61  
62 =cut
63  
64 sub validate_address {
65 my $self = shift;
66 my $email = shift;
67 my $LoginUser = Jifty->app_class('Model','User');
68 my $CurrentUser = Jifty->app_class('CurrentUser');
69
70  
71 return $self->validation_error(
72 address => _("That doesn't look like an email address.") )
73 unless ( $email =~ /\S\@\S/ );
74  
75 $self->user_object(
76 $LoginUser->new( current_user => $CurrentUser->superuser ) );
77 $self->user_object->load_by_cols( email => $email );
78 return $self->validation_error(
79 address => _("It doesn't look like there's an account by that name.") )
80 unless ( $self->user_object->id );
81  
82 return $self->validation_ok('address');
83 }
84  
85 =head2 take_action
86  
87 Send out a Reminder email giving a link to a password-reset form.
88  
89 =cut
90  
91 sub take_action {
92 my $self = shift;
93 Jifty->app_class('Notification','ConfirmLostPassword')->new(
94 to => $self->user_object )->send;
95 return $self->result->message(
96 _("A link to reset your password has been sent to your email account."));
97 }
98  
99 1;
100