diff options
Diffstat (limited to 'lib/Reaction/InterfaceModel/Action/User/Login.pm')
-rw-r--r-- | lib/Reaction/InterfaceModel/Action/User/Login.pm | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/Reaction/InterfaceModel/Action/User/Login.pm b/lib/Reaction/InterfaceModel/Action/User/Login.pm new file mode 100644 index 0000000..781ec0f --- /dev/null +++ b/lib/Reaction/InterfaceModel/Action/User/Login.pm @@ -0,0 +1,49 @@ +package Reaction::InterfaceModel::Action::User::Login; + +use Reaction::Class; +use aliased 'Reaction::InterfaceModel::Action'; + +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 |