Commit | Line | Data |
7adfd53f |
1 | package Reaction::InterfaceModel::Action::User::ChangePassword; |
2 | |
3 | use Reaction::Class; |
4 | |
d9a3266f |
5 | use Reaction::Types::Core qw(Password); |
6 | |
7adfd53f |
7 | class ChangePassword is 'Reaction::InterfaceModel::Action::User::SetPassword', which { |
d9a3266f |
8 | has old_password => (isa => Password, is => 'rw', lazy_fail => 1); |
7adfd53f |
9 | |
10 | around error_for_attribute => sub { |
11 | my $super = shift; |
12 | my ($self, $attr) = @_; |
13 | if ($attr->name eq 'old_password') { |
14 | return "Old password incorrect" |
15 | unless $self->verify_old_password; |
16 | } |
17 | #return $super->(@_); #commented out because the original didn't super() |
18 | }; |
19 | |
20 | around can_apply => sub { |
21 | my $super = shift; |
22 | my ($self) = @_; |
23 | return 0 unless $self->verify_old_password; |
24 | return $super->(@_); |
25 | }; |
26 | |
27 | implements verify_old_password => as { |
28 | my $self = shift; |
29 | return unless $self->has_old_password; |
30 | |
31 | my $user = $self->target_model; |
32 | return $user->can("check_password") ? |
33 | $user->check_password($self->old_password) : |
34 | $self->old_password eq $user->password; |
35 | }; |
36 | |
37 | }; |
38 | |
39 | 1; |
40 | |
41 | =head1 NAME |
42 | |
43 | Reaction::InterfaceModel::Action::User::ChangePassword |
44 | |
45 | =head1 DESCRIPTION |
46 | |
47 | =head1 METHODS |
48 | |
49 | =head2 old_password |
50 | |
51 | =head2 verify_old_password |
52 | |
53 | =head1 SEE ALSO |
54 | |
55 | L<Reaction::InterfaceModel::Action::DBIC::User::ChangePassword> |
56 | |
57 | =head1 AUTHORS |
58 | |
59 | See L<Reaction::Class> for authors. |
60 | |
61 | =head1 LICENSE |
62 | |
63 | See L<Reaction::Class> for the license. |
64 | |
65 | =cut |