tiny stylistic change
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / User / ResetPassword.pm
1 package Reaction::InterfaceModel::Action::User::ResetPassword;
2
3 use Reaction::Class;
4 use aliased 'Reaction::InterfaceModel::Action::User::SetPassword';
5 use Reaction::Types::Core qw(NonEmptySimpleStr);
6 use namespace::clean -except => [ qw(meta) ];
7
8 extends SetPassword;
9
10 has confirmation_code =>
11     (isa => NonEmptySimpleStr, is => 'rw', lazy_fail => 1);
12
13 has 'user' => (
14     is => 'rw', metaclass => 'Reaction::Meta::Attribute',
15     predicate => 'has_user',
16 );
17
18 around can_apply => sub {
19     my $super = shift;
20     my ($self) = @_;
21     return 0 unless $self->verify_confirmation_code;
22     return $super->(@_);
23 };
24
25 sub verify_confirmation_code {
26   my $self = shift;
27   return unless $self->has_confirmation_code;
28   my $model = $self->target_model;
29   my $supplied_code = $self->confirmation_code;
30   if (defined(my $user = $model->find_by_confirmation_code($supplied_code))) {
31     $self->user($user);
32     return 1;
33   }
34   return;
35 }
36
37 around error_for_attribute => sub {
38   my $super = shift;
39   my ($self, $attr) = @_;
40   if ($attr->name eq 'confirmation_code') {
41     return 'Confirmation code incorrect' unless $self->has_user;
42   }
43   return $super->(@_);
44 };
45
46 sub do_apply {
47   my $self = shift;
48   return $self->user->reset_password($self->new_password);
49 }
50
51 __PACKAGE__->meta->make_immutable;
52
53
54 1;
55
56 =head1 NAME
57
58 Reaction::InterfaceModel::Action::User::ResetPassword
59
60 =head1 DESCRIPTION
61
62 =head2 error_for_attribute
63
64 =head2 confirmation_code
65
66 =head2 verify_confirmation_code
67
68 =head1 SEE ALSO
69
70 L<Reaction::InterfaceModel::Action::DBIC::User::ResetPassword>
71
72 L<Reaction::InterfaceModel::Action::User::Role::ConfirmationCodeSupport>
73
74 =head1 AUTHORS
75
76 See L<Reaction::Class> for authors.
77
78 =head1 LICENSE
79
80 See L<Reaction::Class> for the license.
81
82 =cut