aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/InterfaceModel/Action/User/Login.pm
blob: 31abd8bc8298b5ae626538127bf72a086d6d4266 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Reaction::InterfaceModel::Action::User::Login;

use Reaction::Class;
use aliased 'Reaction::InterfaceModel::Action';
use Reaction::Types::Core qw(SimpleStr Password);

use namespace::clean -except => [ qw(meta) ];
extends Action;



has 'username' => (isa => SimpleStr, is => 'rw', lazy_fail => 1);
has 'password' => (isa => Password,  is => 'rw', lazy_fail => 1);

around error_for_attribute => sub {
  my $super = shift;
  my ($self, $attr) = @_;
  my $result = $super->(@_);
  my $predicate = $attr->get_predicate_method;
  if (defined $result && $self->$predicate) {
    return 'Invalid username or password';
  }
  return;
};
sub do_apply {
  my $self = shift;
  my $target = $self->target_model;
  return $target->login($self->username, $self->password);
};
__PACKAGE__->meta->make_immutable;


1;

=head1 NAME

Reaction::InterfaceModel::Action::User::Login

=head1 DESCRIPTION

=head2 username

=head2 password

=head1 AUTHORS

See L<Reaction::Class> for authors.

=head1 LICENSE

See L<Reaction::Class> for the license.

=cut