-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Plugin.php
198 lines (177 loc) · 6.54 KB
/
Plugin.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php namespace Winter\User;
use App;
use Auth;
use Event;
use Backend;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use Illuminate\Foundation\AliasLoader;
use Winter\User\Classes\UserRedirector;
use Winter\User\Models\MailBlocker;
use Winter\Notify\Classes\Notifier;
class Plugin extends PluginBase
{
/**
* @var boolean Determine if this plugin should have elevated privileges.
*/
public $elevated = true;
public function pluginDetails()
{
return [
'name' => 'winter.user::lang.plugin.name',
'description' => 'winter.user::lang.plugin.description',
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-user',
'homepage' => 'https://github.com/wintercms/wn-user-plugin',
'replaces' => ['RainLab.User' => '~1.6'],
];
}
public function register()
{
$alias = AliasLoader::getInstance();
$alias->alias('Auth', 'Winter\User\Facades\Auth');
App::singleton('user.auth', function () {
return \Winter\User\Classes\AuthManager::instance();
});
App::singleton('redirect', function ($app) {
// overrides with our own extended version of Redirector to support
// seperate url.intended session variable for frontend
$redirector = new UserRedirector($app['url']);
// If the session is set on the application instance, we'll inject it into
// the redirector instance. This allows the redirect responses to allow
// for the quite convenient "with" methods that flash to the session.
if (isset($app['session.store'])) {
$redirector->setSession($app['session.store']);
}
return $redirector;
});
/*
* Apply user-based mail blocking
*/
Event::listen('mailer.prepareSend', function ($mailer, $view, $message) {
return MailBlocker::filterMessage($view, $message);
});
/*
* Compatability with Winter.Notify
*/
$this->bindNotificationEvents();
}
public function registerComponents()
{
return [
\Winter\User\Components\Session::class => 'session',
\Winter\User\Components\Account::class => 'account',
\Winter\User\Components\ResetPassword::class => 'resetPassword'
];
}
public function registerPermissions()
{
return [
'winter.users.access_users' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_users'
],
'winter.users.access_groups' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_groups'
],
'winter.users.access_settings' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.access_settings'
],
'winter.users.impersonate_user' => [
'tab' => 'winter.user::lang.plugin.tab',
'label' => 'winter.user::lang.plugin.impersonate_user'
],
];
}
public function registerNavigation()
{
return [
'user' => [
'label' => 'winter.user::lang.users.menu_label',
'url' => Backend::url('winter/user/users'),
'icon' => 'icon-user',
'iconSvg' => 'plugins/winter/user/assets/images/user-icon.svg',
'permissions' => ['winter.users.*'],
'order' => 500,
'sideMenu' => [
'users' => [
'label' => 'winter.user::lang.users.menu_label',
'icon' => 'icon-user',
'url' => Backend::url('winter/user/users'),
'permissions' => ['winter.users.access_users']
],
'usergroups' => [
'label' => 'winter.user::lang.groups.menu_label',
'icon' => 'icon-users-viewfinder',
'url' => Backend::url('winter/user/usergroups'),
'permissions' => ['winter.users.access_groups']
]
]
]
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'winter.user::lang.settings.menu_label',
'description' => 'winter.user::lang.settings.menu_description',
'category' => SettingsManager::CATEGORY_USERS,
'icon' => 'icon-user-gear',
'class' => 'Winter\User\Models\Settings',
'order' => 500,
'permissions' => ['winter.users.access_settings']
]
];
}
public function registerMailTemplates()
{
return [
'winter.user::mail.activate',
'winter.user::mail.welcome',
'winter.user::mail.restore',
'winter.user::mail.new_user',
'winter.user::mail.reactivate',
'winter.user::mail.invite',
];
}
public function registerNotificationRules()
{
if (!class_exists(\Winter\Notify\Classes\Notifier::class)) {
return [];
}
return [
'groups' => [
'user' => [
'label' => 'User',
'icon' => 'icon-user'
],
],
'events' => [
\Winter\User\NotifyRules\UserActivatedEvent::class,
\Winter\User\NotifyRules\UserRegisteredEvent::class,
],
'actions' => [],
'conditions' => [
\Winter\User\NotifyRules\UserAttributeCondition::class,
],
];
}
protected function bindNotificationEvents()
{
if (!class_exists(\Winter\Notify\Classes\Notifier::class)) {
return;
}
Notifier::bindEvents([
'winter.user.activate' => \Winter\User\NotifyRules\UserActivatedEvent::class,
'winter.user.register' => \Winter\User\NotifyRules\UserRegisteredEvent::class,
]);
Notifier::instance()->registerCallback(function ($manager) {
$manager->registerGlobalParams([
'user' => Auth::getUser()
]);
});
}
}