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