do not include .git directory
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / User / ChangePassword.pm
CommitLineData
7adfd53f 1package Reaction::InterfaceModel::Action::User::ChangePassword;
2
3use Reaction::Class;
4
d9a3266f 5use Reaction::Types::Core qw(Password);
6
81393881 7use namespace::clean -except => [ qw(meta) ];
8extends 'Reaction::InterfaceModel::Action::User::SetPassword';
9
10
11has old_password => (isa => Password, is => 'rw', lazy_fail => 1);
12
13around 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
23around can_apply => sub {
24 my $super = shift;
25 my ($self) = @_;
26 return 0 unless $self->verify_old_password;
27 return $super->(@_);
28};
29sub 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 421;
43
44=head1 NAME
45
46Reaction::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
58L<Reaction::InterfaceModel::Action::DBIC::User::ChangePassword>
59
60=head1 AUTHORS
61
62See L<Reaction::Class> for authors.
63
64=head1 LICENSE
65
66See L<Reaction::Class> for the license.
67
68=cut