-
Notifications
You must be signed in to change notification settings - Fork 152
/
Plugin.php
227 lines (207 loc) · 6.89 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php namespace RainLab\User;
use App;
use Event;
use Config;
use Backend;
use System\Classes\PluginBase;
use System\Classes\SettingsManager;
use RainLab\User\Classes\UserRedirector;
use RainLab\User\Classes\UserProvider;
/**
* Plugin base class
*/
class Plugin extends PluginBase
{
/**
* pluginDetails
*/
public function pluginDetails()
{
return [
'name' => "User",
'description' => "Front-end user management.",
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-user',
'homepage' => 'https://github.com/rainlab/user-plugin',
'hint' => 'user'
];
}
/**
* register the service provider.
*/
public function register()
{
$this->registerAuthConfiguration();
$this->registerSingletons();
$this->registerAuthProvider();
$this->registerCustomRedirector();
$this->registerMailBlocker();
$this->registerConsoleCommand('user.migratev1', \RainLab\User\Console\MigrateV1Command::class);
}
/**
* boot the module events.
*/
public function boot()
{
}
/**
* registerAuthConfiguration
*/
protected function registerAuthConfiguration()
{
if (!Config::get('auth.defaults')) {
Config::set('auth', Config::get('rainlab.user::auth'));
}
}
/**
* registerSingletons
*/
protected function registerSingletons()
{
$this->app->singleton('user.twofactor', \RainLab\User\Classes\TwoFactorManager::class);
// Laravel services
$this->app->alias('auth', \RainLab\User\Classes\AuthManager::class);
$this->app->alias('auth', \Illuminate\Contracts\Auth\Factory::class);
$this->app->alias('auth.driver', \Illuminate\Contracts\Auth\Guard::class);
$this->app->singleton('auth', fn ($app) => new \RainLab\User\Classes\AuthManager($app));
$this->app->singleton('auth.driver', fn ($app) => $app['auth']->guard());
}
/**
* registerAuthProvider extends the auth manager to include a custom provider
*/
protected function registerAuthProvider()
{
$this->app->auth->provider('user', function ($app, array $config) {
return new UserProvider($app['hash'], $config['model']);
});
}
/**
* registerCustomRedirector extends the redirector session state to use
* a unique key for the frontend
*/
protected function registerCustomRedirector()
{
// Overrides with our own extended version of Redirector to support
// separate url.intended session variable for frontend
App::singleton('redirect', function ($app) {
$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;
});
}
/**
* registerMailBlocker applies user-based mail blocking
*/
protected function registerMailBlocker()
{
Event::listen('mailer.prepareSend', function ($mailer, $view, $message) {
return \RainLab\User\Models\UserPreference::filterMailMessage($view, $message);
});
}
/**
* registerComponents
*/
public function registerComponents()
{
return [
\RainLab\User\Components\Session::class => 'session',
\RainLab\User\Components\Account::class => 'account',
\RainLab\User\Components\ResetPassword::class => 'resetPassword',
\RainLab\User\Components\Authentication::class => 'authentication',
\RainLab\User\Components\Registration::class => 'registration',
];
}
/**
* registerPermissions
*/
public function registerPermissions()
{
return [
'rainlab.users.access_users' => [
'tab' => "Users",
'label' => "Manage Users"
],
'rainlab.users.access_groups' => [
'tab' => "Users",
'label' => "Manage User Groups"
],
'rainlab.users.access_settings' => [
'tab' => "Users",
'label' => "Manage User Settings"
],
'rainlab.users.impersonate_user' => [
'tab' => "Users",
'label' => "Impersonate Users"
],
'rainlab.user.timelines' => [
'tab' => "Users",
'label' => "Manage Timelines"
],
];
}
/**
* registerNavigation
*/
public function registerNavigation()
{
return [
'user' => [
'label' => "Users",
'url' => Backend::url('rainlab/user/users'),
'icon' => 'icon-user',
'iconSvg' => 'plugins/rainlab/user/assets/images/user-icon.svg',
'permissions' => ['rainlab.users.*'],
'order' => 500,
'sideMenu' => [
'timelines' => [
'label' => "Activity",
'icon' => 'icon-bars',
'url' => Backend::url('user/timelines'),
'permissions' => ['rainlab.user.timelines']
],
'users' => [
'label' => "Users",
'icon' => 'icon-user',
'url' => Backend::url('rainlab/user/users'),
'permissions' => ['rainlab.users.access_users']
],
]
]
];
}
/**
* registerSettings
*/
public function registerSettings()
{
return [
'settings' => [
'label' => "User Settings",
'description' => "Manage user authentication, registration and activation settings.",
'category' => SettingsManager::CATEGORY_USERS,
'icon' => 'icon-user-actions-key',
'class' => \RainLab\User\Models\Setting::class,
'order' => 500,
'permissions' => ['rainlab.users.access_settings']
]
];
}
/**
* registerMailTemplates
*/
public function registerMailTemplates()
{
return [
'user:invite_email' => 'rainlab.user::mail.invite_email',
'user:welcome_email' => 'rainlab.user::mail.welcome_email',
'user:recover_password' => 'rainlab.user::mail.recover_password',
'user:verify_email' => 'rainlab.user::mail.verify_email',
'user:new_user_internal' => 'rainlab.user::mail.new_user_internal',
];
}
}