Apache2::REST::Handler::login - POC for a login mecanism


Apache2-REST documentation Contained in the Apache2-REST distribution.

Index


Code Index:

NAME

Top

Apache2::REST::Handler::login - POC for a login mecanism

GET

Returns a uid and a authentication token

isAuth

Allow GET or POST


Apache2-REST documentation Contained in the Apache2-REST distribution.
package Apache2::REST::Handler::login ;
use strict ;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use base qw/Apache2::REST::Handler/ ;

my $SERIAL = 0 ;

sub GET{
    my ( $self , $req , $resp ) = @_ ;
    
    my $email = $req->param('email') ;
    my $password = $req->param('password') ;
    
    ## DUMMY
    if ( $email ne 'fail'){
        my $uid = $SERIAL++ ;
        $resp->data()->{'uid'} = $uid ;
        $resp->data()->{'authentication'} = md5_hex($uid.'toto') ;
        return Apache2::Const::HTTP_OK ;
    }
    ## DUMMY FAILURE
    $resp->message('Authentication failed') ;
    return Apache2::Const::HTTP_UNAUTHORIZED ;
    
}

sub isAuth{
    my ($self , $method , $req ) = @_ ;
    return $method eq 'GET' || 
           $method eq 'POST' ;
}

1;