Catalyst Introducing Catalyst #42

Authentication Controller

sub login :Global ActionClass('REST') {}
sub login_GET {
    my ($self, $c) = @_;
    $c->stash->{template} = 'login.tt';
}
sub login_POST {
    my ($self, $c) = @_;
    if($c->authenticate({
        map { $_ => $c->req->params->{$_} } qw/username password/
    })){
        $c->flash->{message} = 'You have been logged in.';
        my $from = delete $c->session->{login_from} ||
          $c->uri_for('/');
        $c->res->redirect($from);
    }
    else {
        $c->flash->{message} = 'You could not be logged in.';
        $c->res->redirect($c->uri_for('/login'));
    }
}
continued...
""