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