Commit 8d1c669a authored by Yadd's avatar Yadd

#595 in progress...

parent a16d452a
...@@ -120,8 +120,8 @@ sub _del { ...@@ -120,8 +120,8 @@ sub _del {
sub jsonResponse { sub jsonResponse {
my ( $self, $path, $query ) = @_; my ( $self, $path, $query ) = @_;
my $res = $self->_get( $path, $query ) my $res = $self->_get( $path, $query )
or die "Manager lib has refused my get, aborting"; or die "PSGI lib has refused my get, aborting";
die "Manager lib does not return a 200 code, aborting" die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 ); unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON'; my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href; return $href;
...@@ -130,8 +130,8 @@ sub jsonResponse { ...@@ -130,8 +130,8 @@ sub jsonResponse {
sub jsonPostResponse { sub jsonPostResponse {
my ( $self, $path, $query, $body, $type, $len ) = @_; my ( $self, $path, $query, $body, $type, $len ) = @_;
my $res = $self->_post( $path, $query, $body, $type, $len ) my $res = $self->_post( $path, $query, $body, $type, $len )
or die "Manager lib has refused my post, aborting"; or die "PSGI lib has refused my post, aborting";
die "Manager lib does not return a 200 code, aborting" die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 ); unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON'; my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href; return $href;
...@@ -140,8 +140,8 @@ sub jsonPostResponse { ...@@ -140,8 +140,8 @@ sub jsonPostResponse {
sub jsonPutResponse { sub jsonPutResponse {
my ( $self, $path, $query, $body, $type, $len ) = @_; my ( $self, $path, $query, $body, $type, $len ) = @_;
my $res = $self->_put( $path, $query, $body, $type, $len ) my $res = $self->_put( $path, $query, $body, $type, $len )
or die "Manager lib has refused my put, aborting"; or die "PSGI lib has refused my put, aborting";
die "Manager lib does not return a 200 code, aborting" die "PSGI lib does not return a 200 code, aborting"
unless ( $res->[0] == 200 ); unless ( $res->[0] == 200 );
my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON'; my $href = from_json( $res->[2]->[0] ) or die 'Response is not JSON';
return $href; return $href;
......
...@@ -71,7 +71,7 @@ has QUERY_STRING => ( ...@@ -71,7 +71,7 @@ has QUERY_STRING => (
); );
sub _urlcode2params { sub _urlcode2params {
my ( $self, $str ) = shift; my ( $self, $str ) = @_;
my @tmp = $str ? map { uri_unescape($_) } split( /&/, $str ) : (); my @tmp = $str ? map { uri_unescape($_) } split( /&/, $str ) : ();
foreach my $s (@tmp) { foreach my $s (@tmp) {
if ( $s =~ /^(.+?)=(.+)$/ ) { $self->{_params}->{$1} = $2; } if ( $s =~ /^(.+?)=(.+)$/ ) { $self->{_params}->{$1} = $2; }
......
...@@ -99,9 +99,6 @@ sub extractFormInfo { ...@@ -99,9 +99,6 @@ sub extractFormInfo {
# Other parameters # Other parameters
$req->{timezone} = $req->param('timezone'); $req->{timezone} = $req->param('timezone');
# Check user
return PE_MALFORMEDUSER unless $self->get_user;
PE_OK; PE_OK;
} }
......
...@@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Main::Constants; ...@@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Main::Constants;
use strict; use strict;
use Exporter 'import'; use Exporter 'import';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
use constant { use constant {
# Portal errors # Portal errors
...@@ -150,6 +151,7 @@ our @EXPORT = qw( PE_IMG_NOK PE_IMG_OK PE_INFO PE_REDIRECT PE_DONE PE_OK ...@@ -150,6 +151,7 @@ our @EXPORT = qw( PE_IMG_NOK PE_IMG_OK PE_INFO PE_REDIRECT PE_DONE PE_OK
PM_LAST_LOGINS PM_LAST_FAILED_LOGINS PM_OIDC_CONSENT PM_OIDC_SCOPE_OPENID PM_LAST_LOGINS PM_LAST_FAILED_LOGINS PM_OIDC_CONSENT PM_OIDC_SCOPE_OPENID
PM_OIDC_SCOPE_PROFILE PM_OIDC_SCOPE_EMAIL PM_OIDC_SCOPE_ADDRESS PM_OIDC_SCOPE_PROFILE PM_OIDC_SCOPE_EMAIL PM_OIDC_SCOPE_ADDRESS
PM_OIDC_SCOPE_PHONE PM_OIDC_SCOPE_OTHER PM_OIDC_CONFIRM_LOGOUT PM_OIDC_SCOPE_PHONE PM_OIDC_SCOPE_OTHER PM_OIDC_CONFIRM_LOGOUT
HANDLER
); );
our %EXPORT_TAGS = ( 'all' => [ @EXPORT, 'import' ], ); our %EXPORT_TAGS = ( 'all' => [ @EXPORT, 'import' ], );
......
...@@ -11,6 +11,7 @@ package Lemonldap::NG::Portal::Main::Init; ...@@ -11,6 +11,7 @@ package Lemonldap::NG::Portal::Main::Init;
use strict; use strict;
use Mouse; use Mouse;
use Lemonldap::NG::Common::Conf::Constants; use Lemonldap::NG::Common::Conf::Constants;
use Lemonldap::NG::Portal::Main::Constants;
use Lemonldap::NG::Handler::Main::Reload qw/keepConf/; use Lemonldap::NG::Handler::Main::Reload qw/keepConf/;
use Lemonldap::NG::Portal::Main::Plugins; use Lemonldap::NG::Portal::Main::Plugins;
use Regexp::Assemble; use Regexp::Assemble;
...@@ -20,8 +21,6 @@ our $VERSION = '2.0.0'; ...@@ -20,8 +21,6 @@ our $VERSION = '2.0.0';
extends 'Lemonldap::NG::Handler::PSGI::Try', extends 'Lemonldap::NG::Handler::PSGI::Try',
'Lemonldap::NG::Portal::Main::Plugins'; 'Lemonldap::NG::Portal::Main::Plugins';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
# Configuration storage # Configuration storage
has localConfig => ( is => 'rw', default => sub { {} } ); has localConfig => ( is => 'rw', default => sub { {} } );
has conf => ( is => 'rw', default => sub { {} } ); has conf => ( is => 'rw', default => sub { {} } );
......
...@@ -5,6 +5,7 @@ use Mouse; ...@@ -5,6 +5,7 @@ use Mouse;
use Lemonldap::NG::Portal::Main::Constants; use Lemonldap::NG::Portal::Main::Constants;
use Lemonldap::NG::Portal::Main::Request; use Lemonldap::NG::Portal::Main::Request;
use MIME::Base64; use MIME::Base64;
use POSIX qw(strftime);
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
...@@ -21,9 +22,11 @@ sub process { ...@@ -21,9 +22,11 @@ sub process {
my $err = PE_OK; my $err = PE_OK;
while ( my $sub = shift @{ $req->steps } ) { while ( my $sub = shift @{ $req->steps } ) {
if ( ref $sub ) { if ( ref $sub ) {
$self->lmLog( "Processing code ref", 'debug' );
last if ( $sub->($req) ); last if ( $sub->($req) );
} }
else { else {
$self->lmLog( "Processing $sub", 'debug' );
last if ( $err = $self->$sub($req) ); last if ( $err = $self->$sub($req) );
} }
} }
......
...@@ -17,6 +17,7 @@ has datas => ( is => 'rw', default => sub { {} } ); ...@@ -17,6 +17,7 @@ has datas => ( is => 'rw', default => sub { {} } );
# Session datas when created # Session datas when created
has id => ( is => 'rw' ); has id => ( is => 'rw' );
has sessionInfo => ( is => 'rw' ); has sessionInfo => ( is => 'rw' );
has user => ( is => 'rw' );
# Response cookies (list of strings built by cookie()) # Response cookies (list of strings built by cookie())
has respCookies => ( is => 'rw' ); has respCookies => ( is => 'rw' );
......
...@@ -16,8 +16,6 @@ use Lemonldap::NG::Portal::Main::Request; ...@@ -16,8 +16,6 @@ use Lemonldap::NG::Portal::Main::Request;
extends 'Lemonldap::NG::Portal::Main::Process'; extends 'Lemonldap::NG::Portal::Main::Process';
use constant HANDLER => 'Lemonldap::NG::Handler::PSGI::API';
our $VERSION = '2.0.0'; our $VERSION = '2.0.0';
# List constants # List constants
...@@ -86,14 +84,14 @@ sub postLogin { ...@@ -86,14 +84,14 @@ sub postLogin {
'restoreArgs', 'controlUrl', 'restoreArgs', 'controlUrl',
@{ $self->beforeAuth }, &authProcess, @{ $self->beforeAuth }, &authProcess,
@{ $self->betweenAuthAndDatas }, &sessionDatas, @{ $self->betweenAuthAndDatas }, &sessionDatas,
@{ $self->afterdatas }, @{ $self->afterDatas },
] ]
); );
} }
sub authenticatedRequest { sub authenticatedRequest {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
return $self->do( $req, $self->forAuthUser ); return $self->do( $req, [ 'controlUrl', @{ $self->forAuthUser } ] );
} }
# RUNNING METHODS # RUNNING METHODS
......
...@@ -19,9 +19,9 @@ our $VERSION = '2.0.0'; ...@@ -19,9 +19,9 @@ our $VERSION = '2.0.0';
sub init { sub init {
my $self = shift; my $self = shift;
unless ( $self->p->getModule( undef, 'auth' ) =~ /^Demo/ ) { unless ( $self->p->getModule( undef, 'auth' ) =~ /Demo/ ) {
$self->lmLog( "Use UserDBDemo only with AuthDemo", 'error' ); $self->p->error("Use UserDB::Demo only with Auth::Demo");
return PE_ERROR; return 0;
} }
# Sample accounts from Doctor Who characters # Sample accounts from Doctor Who characters
...@@ -53,9 +53,9 @@ sub getUser { ...@@ -53,9 +53,9 @@ sub getUser {
my ( $self, $req ) = @_; my ( $self, $req ) = @_;
# Search by login # Search by login
if ( $req->{user} ) { if ( $req->user ) {
return PE_OK return PE_OK
if ( defined $self->{_demoAccounts}->{ $req->{user} } ); if ( defined $self->{_demoAccounts}->{ $req->user } );
} }
# Search by mail # Search by mail
......
use Test::More; use Test::More;
use strict; use strict;
use IO::String;
require 't/test-lib.pm'; require 't/test-lib.pm';
print STDERR Dumper(&client->_get('/')); my $res;
ok( $res = &client->_get('/'), 'Unauth JSON request' );
ok( $res->[0] == 401, 'Response is 401' ) or explain( $res, 401 );
count(2);
#ok( $res = &client->jsonPostResponse('/','',IO::String->new('user=dwho&password=dwho'),'application/x-www-form-urlencoded',23), 'Auth query');
#count(1);
done_testing( count() ); done_testing( count() );
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment