Avoid circular refs with target_model for login actions
[catagits/Reaction.git] / lib / Reaction / InterfaceModel / Action / User / Login.pm
CommitLineData
7adfd53f 1package Reaction::InterfaceModel::Action::User::Login;
2
3use Reaction::Class;
4use aliased 'Reaction::InterfaceModel::Action';
d9a3266f 5use Reaction::Types::Core qw(SimpleStr Password);
7adfd53f 6
81393881 7use namespace::clean -except => [ qw(meta) ];
8extends Action;
9
81cb15f7 10# Avoid circular ref with target_model for Auth controller login actions.
11sub BUILD { Scalar::Util::weaken($_[0]->{target_model}) }
81393881 12
13has 'username' => (isa => SimpleStr, is => 'rw', lazy_fail => 1);
14has 'password' => (isa => Password, is => 'rw', lazy_fail => 1);
15
16around error_for_attribute => sub {
17 my $super = shift;
18 my ($self, $attr) = @_;
19 my $result = $super->(@_);
20 my $predicate = $attr->get_predicate_method;
21 if (defined $result && $self->$predicate) {
22 return 'Invalid username or password';
23 }
24 return;
25};
26sub do_apply {
27 my $self = shift;
28 my $target = $self->target_model;
29 return $target->login($self->username, $self->password);
7adfd53f 30};
81393881 31__PACKAGE__->meta->make_immutable;
32
7adfd53f 33
341;
35
36=head1 NAME
37
38Reaction::InterfaceModel::Action::User::Login
39
40=head1 DESCRIPTION
41
42=head2 username
43
44=head2 password
45
46=head1 AUTHORS
47
48See L<Reaction::Class> for authors.
49
50=head1 LICENSE
51
52See L<Reaction::Class> for the license.
53
54=cut