2017-02-23 22:46:00 +01:00
|
|
|
package Lemonldap::NG::Portal::UserDB::REST;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_ERROR
|
|
|
|
PE_OK
|
|
|
|
PE_USERNOTFOUND
|
|
|
|
);
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Common::Module', 'Lemonldap::NG::Portal::Lib::REST';
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
|
|
|
# INITIALIZATION
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# Add warning in log
|
|
|
|
unless ( $self->conf->{restUserDBUrl} ) {
|
|
|
|
$self->logger->error('No User REST URL given');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# RUNNING METHODS
|
|
|
|
|
|
|
|
sub getUser {
|
2018-01-22 21:57:48 +01:00
|
|
|
my ( $self, $req, %args ) = @_;
|
|
|
|
my $res;
|
|
|
|
$res = eval {
|
|
|
|
$self->restCall(
|
|
|
|
(
|
|
|
|
$args{useMail}
|
|
|
|
? $self->conf->{restMailDBUrl} || $self->conf->{restUserDBUrl}
|
|
|
|
: $self->conf->{restUserDBUrl}
|
|
|
|
),
|
|
|
|
{ user => $req->user }
|
|
|
|
);
|
2017-02-23 22:46:00 +01:00
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$self->logger->error("UserDB REST error: $@");
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
unless ( $res->{result} ) {
|
|
|
|
$self->userLogger->warn( 'User ' . $req->user . ' not found' );
|
|
|
|
return PE_USERNOTFOUND;
|
|
|
|
}
|
2017-02-24 06:37:32 +01:00
|
|
|
$req->datas->{restUserDBInfo} = $res->{info} || {};
|
2017-02-23 22:46:00 +01:00
|
|
|
return PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setSessionInfo {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
$req->sessionInfo->{$_} = $req->datas->{restUserDBInfo}->{$_}
|
|
|
|
foreach ( keys %{ $req->datas->{restUserDBInfo} } );
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setGroups {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|