diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDBDBI.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDBDBI.pm index fc37e1846..c0db1c4c4 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDBDBI.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/UserDBDBI.pm @@ -9,7 +9,7 @@ use strict; use Lemonldap::NG::Portal::Simple; use Lemonldap::NG::Portal::_DBI; #inherits -our $VERSION = '1.0.0'; +our $VERSION = '1.2.3'; ## @apmethod int userDBInit() # Set default values @@ -65,6 +65,31 @@ sub getUser { $self->lmLog( "User $user not found", 'notice' ); return PE_BADCREDENTIALS; } + + # In mail process, get user value + if ( $self->{mail} ) { + $table = $self->{dbiAuthTable}; + $pivot = $self->{dbiAuthLoginCol}; + $user = $self->{entry}->{ $self->{userPivot} }; + eval { + $sth = $dbh->prepare("SELECT * FROM $table WHERE $pivot=?"); + $sth->execute($user); + }; + if ($@) { + $self->lmLog( "DBI error: $@", 'error' ); + return PE_ERROR; + } + + my $results; + + unless ( $results = $sth->fetchrow_hashref() ) { + $self->lmLog( "User $user not found", 'notice' ); + return PE_BADCREDENTIALS; + } + + $self->{user} = $results->{$pivot}; + } + PE_OK; } @@ -74,6 +99,9 @@ sub getUser { sub setSessionInfo { my $self = shift; + # Set _user unless already defined + $self->{sessionInfo}->{_user} ||= $self->{user}; + # Return if no data to collect return PE_OK unless ( $self->{exportedVars}