-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathPlugin.php
More file actions
executable file
·84 lines (72 loc) · 2.39 KB
/
Plugin.php
File metadata and controls
executable file
·84 lines (72 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php namespace KhoaTD\LDAP;
use Adldap\Laravel\AdldapServiceProvider;
use Adldap\Laravel\Facades\Adldap;
use App;
use Backend\Controllers\Users;
use KhoaTD\LDAP\Facades\LDAPBackendAuth;
use KhoaTD\LDAP\Services\LDAPAuthManager;
use Illuminate\Foundation\AliasLoader;
use October\Rain\Support\Facades\Flash;
use System\Classes\PluginBase;
use Event;
use Session;
class Plugin extends PluginBase
{
public $elevated = true;
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
App::register(AdldapServiceProvider::class);
AliasLoader::getInstance()->alias('Adldap', Adldap::class);
AliasLoader::getInstance()->alias('LDAPBackendAuth', LDAPBackendAuth::class);
App::singleton('backend.ldap_auth', function () {
return LDAPAuthManager::instance();
});
Event::listen('backend.auth.extendSigninView', function($controller) {
$this->hookSigninForm($controller);
});
Event::listen('backend.form.extendFields', function($widget) {
$this->addFieldsToUserForm($widget);
});
Event::listen('backend.list.extendColumns', function($widget) {
$this->addFieldsToUserList($widget);
});
}
protected function hookSigninForm($controller) {
$controller->addJs('/plugins/khoatd/ldap/assets/js/override-auth.js');
$message = Session::get('message');
if(!empty($message)) {
Flash::error($message);
}
}
protected function addFieldsToUserForm($widget) {
if (!$widget->getController() instanceof Users) {
return;
}
$widget->addFields([
'khoatd_ldap_user_type' => [
'label' => 'User type',
'comment' => '(LDAP user if you want to connect with LDAP, CMS user if you want the user is managed inside the CMS)',
'type' => 'dropdown',
'options' => [
'ldap' => 'LDAP user',
'cms' => 'CMS user',
]
]
]);
}
protected function addFieldsToUserList($widget) {
if (!$widget->getController() instanceof Users) {
return;
}
$widget->addColumns([
'khoatd_ldap_user_type' => [
'label' => 'User type'
]
]);
}
}