aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/InterfaceModel/Action/User/Login.pm
blob: 0bc3d9758ca2be487bdc4e3e19dc275a3a7bcafd (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
package Reaction::InterfaceModel::Action::User::Login;

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

class Login, is Action, which {

  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->predicate;
    if (defined $result && $self->$predicate) {
      return 'Invalid username or password';
    }
    return;
  };

  implements do_apply => as {
    my $self = shift;
    my $target = $self->target_model;
    return $target->login($self->username, $self->password);
  };
};

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