Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get user profile image from Active Directory(ldap) #10160

Closed
imRezaAlie opened this issue Oct 3, 2021 · 4 comments
Closed

get user profile image from Active Directory(ldap) #10160

imRezaAlie opened this issue Oct 3, 2021 · 4 comments

Comments

@imRezaAlie
Copy link

Hi Dears,
how can i get user profile image from Active Directory(ldap)?

regards,

Originally posted by @imRezaAlie in #10143

@welcome
Copy link

welcome bot commented Oct 3, 2021

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@imRezaAlie imRezaAlie changed the title Hi Dears, get user profile image from Active Directory(ldap) Oct 3, 2021
@snipe
Copy link
Owner

snipe commented Oct 3, 2021

That’s not possible at this time.

@imRezaAlie
Copy link
Author

Hi Dear @snipe ,
i can retrieve user thumbnailPhoto from LDAP:
steps 1:
add new column ( ldap_avatar) and fillable in related Model
step 2 :
create new command => LdapAvatar:sync
and write this code:
`
public function handle()
{
ini_set('max_execution_time', 60000);
ini_set('memory_limit', '5000M');
$ldapPort = Setting::getSettings()->ldapPort;
$ldapHost = Setting::getSettings()->ldapPort;
$ldapUserName = Setting::getSettings()->ldap_uname;
$ldapPassword = '*************';
$ldapBaseDn = Setting::getSettings()->ldap_basedn;
$users = User::all();
$connection = @ldap_connect($ldapHost, $ldapPort);
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_NETWORK_TIMEOUT, 20);
ldap_set_option($connection, LDAP_OPT_SIZELIMIT, -1);

ldap_bind($connection, $ldapUserName, $ldapPassword);
if (!$connection) {
    \Log::debug('Could not connect to LDAP server at ' . $ldapHost . '. Please check your LDAP server name and port number in your settings.');
}
foreach ($users as $user) {
    $search_filter = '(&(mail=' . $user->email . '))';
    $attributes = array();
    $attributes[] = 'thumbnailPhoto';
    $search_results = @ldap_search($connection, $ldapBaseDn, $search_filter, $attributes);
    $entries = ldap_get_entries($connection, $search_results);
    if ($entries['count'] > 0) {
        if (isset($entries[0]['thumbnailphoto'][0])) {
            $img = base64_encode($entries[0]['thumbnailphoto'][0]);
            User::findOrFail($user->id)->update(['ldap_avatar' => $img]);
        }
    }

}
ldap_close($connection);

`

step 3 :
add this line in related Blade
<img src="data:image/jpeg;base64,<?php echo base64_encode($ldap_avatar); ?>"/>

@SonGokussj4
Copy link

Hi. I see this as closed. Was this resolved for the newest version? Gitea just released a version that reads thumbnailPhoto and it's working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants