1. Go to this page and download the library: Download rgergo67/openldap library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rgergo67 / openldap example snippets
/*
* Package Service Providers...
*/
\Rgergo67\Openldap\OpenldapServiceProvider::class,
php
/**
* Gets the dn attribute.
*
* @return string The dn attribute.
*/
public function getDnAttribute(){
$baseUserDn = $this->isStudent()
? config('openldap.base_student_dn')
: config('openldap.base_employee_dn');
return config('openldap.login_attribute') . "=" . $this->uid . "," . $baseUserDn;
}
php
/**
* Gets the ldap format attribute.
*
* @return array The ldap format attribute.
*/
public function getLdapFormatAttribute(){
return [
"objectClass" => config('openldap.user_object_class'),
'cn' => $this->name,
'sn' => $this->name,
'mail' => $this->email,
'gidNumber' => 1,
'homeDirectory' => '/home/' . $this->username,
'uid' => $this->uid,
'uidNumber' => 67
];
}
public function getOldDnAttribute()
{
return "uid={$this->getOriginal('uid')},{$this->baseEmployeeDn}";
}
// if all groups were deleted, return
if(!request('groups'))
return true;
$this->openldap->deleteUserFromAllGroups($user);
foreach(request('groups') as $groupId){
$group = Group::findOrFail($groupId);
$this->openldap->addUserToGroup($user, $group->dn);
}