package LATMOS::Accounts::Web::Controller::Login;
use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller'; }

=head1 NAME

LATMOS::Accounts::Web::Controller::Login - Catalyst Controller

=head1 DESCRIPTION

Catalyst Controller.

=head1 METHODS

=cut

sub begin : Private {
    my ( $self, $c ) = @_;
    $c->forward('/needlogin');
    return 1;
}

=head2 index

=cut

sub index :Path :Args(0) {
    my ( $self, $c ) = @_;

    if ($c->req->param('username')) {
        if ($c->authenticate({
                username => $c->req->param('username') || '',
                password => $c->req->param('password') || '',
                ssl      => $c->req->param('use_ssl')  || '',
        })) {
            my $redirurl = $c->session->{redirurl} || $c->uri_for('/');
            $redirurl->query_form(%{ $c->session->{redirparam} || {}});
            $c->session->{redirurl} = undef;
            $c->session->{redirparam} = undef;
            $c->res->redirect($redirurl);
        } else {
            # invalid login...
        }
    }
}

=encoding utf8

=head1 AUTHOR

Olivier Thauvin,Guyancourt - B1428,+33 1 80285052,

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

__PACKAGE__->meta->make_immutable;

1;
