2016-05-19 07:11:50 +02:00
|
|
|
package Lemonldap::NG::Portal::UserDB::DBI;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2016-05-22 14:22:59 +02:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_ERROR PE_BADCREDENTIALS);
|
2016-05-19 07:11:50 +02:00
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Lib::DBI';
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# PROPERTIES
|
|
|
|
|
2016-05-19 07:11:50 +02:00
|
|
|
has table => (
|
|
|
|
is => 'rw',
|
|
|
|
builder => sub {
|
|
|
|
my $conf = $_[0]->{conf};
|
|
|
|
return $conf->{dbiUserTable} || $conf->{dbiAuthTable};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
has pivot => (
|
|
|
|
is => 'rw',
|
|
|
|
builder => sub {
|
|
|
|
my $conf = $_[0]->{conf};
|
|
|
|
return $conf->{userPivot} || $conf->{dbiAuthLoginCol};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
has exportedVars => (
|
|
|
|
is => 'rw',
|
|
|
|
builder => sub {
|
|
|
|
my $conf = $_[0]->{conf};
|
|
|
|
return { %{ $conf->{exportedVars} }, %{ $conf->{dbiExportedVars} } };
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-06-09 20:40:20 +02:00
|
|
|
# RUNNING METHODS
|
|
|
|
|
2016-05-19 07:11:50 +02:00
|
|
|
sub getUser {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my $table = $self->table;
|
|
|
|
my $pivot = $self->pivot;
|
|
|
|
my $user = $req->{user};
|
|
|
|
my $sth;
|
|
|
|
eval {
|
|
|
|
$sth = $self->dbh->prepare("SELECT * FROM $table WHERE $pivot=?");
|
|
|
|
$sth->execute($user);
|
|
|
|
};
|
|
|
|
if ($@) {
|
2016-07-20 09:28:20 +02:00
|
|
|
|
|
|
|
# If connection isn't available, error is displayed by dbh()
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("DBI error: $@") if ( $self->_dbh );
|
2016-05-19 07:11:50 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
unless ( $req->datas->{entry} = $sth->fetchrow_hashref() ) {
|
2017-02-15 15:16:59 +01:00
|
|
|
$self->userLogger->warn("User $user not found");
|
2016-05-19 07:11:50 +02:00
|
|
|
return PE_BADCREDENTIALS;
|
|
|
|
}
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setSessionInfo {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Set _user unless already defined
|
|
|
|
$req->{sessionInfo}->{_user} ||= $req->user;
|
|
|
|
|
|
|
|
foreach my $var ( keys %{ $self->exportedVars } ) {
|
|
|
|
my $attr = $self->exportedVars->{$var};
|
|
|
|
$req->{sessionInfo}->{$var} = $req->datas->{entry}->{$attr}
|
|
|
|
if ( defined $self->{entry}->{$attr} );
|
|
|
|
}
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub setGroups {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|