logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Lemonldap::NG::Handler::PSGI::Try - Special handler for Lemonldap::NG Portal

Authors

       LemonLDAP::NG team <http://lemonldap-ng.org/team>

Bug Report

       Use       OW2       system       to       report       bug       or       ask        for        features:
       <https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>

Description

       Lemonldap::NG::Handler::PSGI::Try is a Lemonldap::NG::Handler::PSGI::Router package that provides 2 REST
       routers: one for authenticated users and one for unauthenticated users.

Download

       Lemonldap::NG is available at <https://lemonldap-ng.org/download>

Methods

       Same as Lemonldap::NG::Handler::PSGI::Router (inherits from Lemonldap::NG::Common::PSGI::Router) except
       that:

       addRoute() must be replaced by addAuthRoute() or addUnauthRoute()defaultRoute() must be replaced by defaultAuthRoute() or defaultUnauthRoute()

       Note  also  that  user  session  datas  are  available in $req parameter (first argument received by REST
       methods):

       $req->userData() returns a hash reference containing user session data

Name

       Lemonldap::NG::Handler::PSGI::Try - Special handler for Lemonldap::NG Portal

See Also

       See Lemonldap::NG::Common::PSGI::Router for more.

Synopsis

         package My::PSGI;

         use base Lemonldap::NG::Handler::PSGI::Try;

         sub init {
           my ($self,$args) = @_;

           # Declare REST routes for authenticated users (could be HTML templates or
           # methods)
           $self->addAuthRoute ( 'index.html', undef, ['GET'] )
                ->addAuthRoute ( books => { ':book' => 'booksMethod' }, ['GET', 'POST'] );

           # Default route (ie: PATH_INFO == '/')
           $self->defaultAuthRoute('index.html');

           # Same for unauthenticated users
           $self->addUnauthRoute ( 'login.html', undef, ['GET'] )
                ->addUnauthRoute ( 'login', undef, ['POST'] );
           $self->defaultUnauthRoute('login.html');

           # Return a boolean. If false, then error message has to be stored in
           # $self->error
           return 1;
         }

         sub booksMethod {
           my ( $self, $req, @otherPathInfo ) = @_;

           # Will be called only if authorized
           my $userId = $self->userId;
           my $book = $req->params('book');
           my $method = $req->method;
           ...
           $self->sendJSONresponse(...);
         }

See Also