nuSait / nuldap-laravel
该包最新版本(0.2.5)没有可用的许可证信息。
0.2.5
2016-04-29 15:13 UTC
Requires
- php: >=5.3.0
- fzaninotto/faker: ^1.5
- illuminate/contracts: ~5.1
- illuminate/support: ~5.1
- nusait/nuldap: ^2.1
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-23 12:53:05 UTC
README
这是一个专为西北大学设计的 LDAP 包。(但可以扩展到其他实体)
通过 Composer 安装
composer require nusait/nuldap-laravel
然后更新 composer
composer update
Laravel
将服务提供者添加到 config/app.php
Nusait\Nuldap\NuldapServiceProvider::class,
发布配置
php artisan vendor:publish --provider="Nusait\Nuldap\NuldapServiceProvider"
要使用假 Ldap,请确保在 .env
文件中添加以下行
ldap_fake=true
当使用 NuldapFake 时,任何搜索都将返回一个使用 Faker 预填充数据的用户。无论你为字段提供的搜索词是什么,都会返回该字段的值,例如 searchNetid('asdf')
将返回一个具有 ['netid'] = 'asdf'
的用户。为了模拟找不到用户,请在查询前添加 nf-
,例如 searchNetid('nf-blah')
,它将找不到该用户。
新实例
$ldap = \App::make('ldap')
或 $ldap = app('ldap')
验证
$ldap->validate($netid, $password);
返回一个布尔值
搜索
您可以按 netid、电子邮件、emplid 或 studentid 进行搜索。
$ldap->search('netid', $netid); $ldap->search('email', $email); $ldap->search('emplid', $emplid); $ldap->search('studentid', $studentid);
这返回原始 ldap 元数据。
您也可以使用魔术方法进行搜索
$ldap->searchNetid($netid); $ldap->searchEmail($email); $ldap->searchEmplid($emplid); $ldap->searchStudentid($studentid);
解析用户
$ldap->parseUser($ldapUser [, $transformer ]);
您可以将用户的原始元数据解析为关联数组。您可以向函数传递自己的转换器。转换器必须实现 Contracts 文件夹中的 TransformerInterface。
默认转换映射以下键和值
return [ 'netid' => $this->getSetValueOrNull($ldapUser, 'uid'), 'phone' => $this->getSetValueOrNull($ldapUser, 'telephonenumber'), 'email' => $this->getSetValueOrNull($ldapUser, 'mail'), 'title' => $this->getSetValueOrNull($ldapUser, 'title'), 'first_name' => $this->getSetValueOrNull($ldapUser, 'givenname'), 'last_name' => $this->getSetValueOrNull($ldapUser, 'sn'), 'displayname' => $this->getSetValueOrNull($ldapUser, 'displayname'), 'emplid' => (int)$this->getSetValueOrNull($ldapUser, 'employeenumber'), 'studentid' => (int)$this->getSetValueOrNull($ldapUser, 'nustudentnumber') ];