-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Extension.php
135 lines (117 loc) · 4.6 KB
/
Extension.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
<?php
namespace Igniter\User;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\RateLimiter;
use Main\Facades\Auth;
class Extension extends \System\Classes\BaseExtension
{
public function register()
{
$this->registerEventGlobalParams();
$this->registerRequestRebindHandler();
}
public function boot()
{
$this->configureRateLimiting();
}
public function registerAutomationRules()
{
return [
'events' => [
'igniter.user.register' => \Igniter\User\AutomationRules\Events\CustomerRegistered::class,
],
'actions' => [],
'conditions' => [
\Igniter\User\AutomationRules\Conditions\CustomerAttribute::class,
],
];
}
public function registerComponents()
{
return [
\Igniter\User\Components\Session::class => [
'code' => 'session',
'name' => 'lang:igniter.user::default.session.component_title',
'description' => 'lang:igniter.user::default.session.component_desc',
],
\Igniter\User\Components\Account::class => [
'code' => 'account',
'name' => 'lang:igniter.user::default.account.component_title',
'description' => 'lang:igniter.user::default.account.component_desc',
],
\Igniter\User\Components\ResetPassword::class => [
'code' => 'resetPassword',
'name' => 'lang:igniter.user::default.reset.component_title',
'description' => 'lang:igniter.user::default.reset.component_desc',
],
\Igniter\User\Components\AddressBook::class => [
'code' => 'accountAddressBook',
'name' => 'lang:igniter.user::default.addressbook.component_title',
'description' => 'lang:igniter.user::default.addressbook.component_desc',
],
];
}
public function registerMailTemplates()
{
return [
'igniter.user::mail.password_reset' => 'lang:igniter.user::default.text_mail_password_reset',
'igniter.user::mail.password_reset_request' => 'lang:igniter.user::default.text_mail_password_reset_request',
'igniter.user::mail.registration' => 'lang:igniter.user::default.text_mail_registration',
'igniter.user::mail.registration_alert' => 'lang:igniter.user::default.text_mail_registration_alert',
'igniter.user::mail.activation' => 'lang:igniter.user::default.text_mail_activation',
];
}
public function registerActivityTypes()
{
return [
ActivityTypes\CustomerRegistered::class => 'customerRegistered',
];
}
protected function registerEventGlobalParams()
{
if (class_exists(\Igniter\Automation\Classes\EventManager::class)) {
\Igniter\Automation\Classes\EventManager::instance()->registerCallback(function ($manager) {
$manager->registerGlobalParams([
'customer' => Auth::customer(),
]);
});
}
}
protected function registerRequestRebindHandler()
{
$this->app->rebinding('request', function ($app, $request) {
if ($request instanceof \Dingo\Api\Http\Request)
return;
$request->setUserResolver(function () use ($app) {
if ($app->runningInAdmin())
return $app['admin.auth']->getUser();
return $app['auth']->getUser();
});
});
}
protected function configureRateLimiting()
{
RateLimiter::for('web', function (\Illuminate\Http\Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->getKey() ?: $request->ip());
});
if ($this->app->runningInAdmin())
return;
$this->app->make(\Illuminate\Contracts\Http\Kernel::class)
->appendMiddlewareToGroup('web', \Igniter\User\Middleware\ThrottleRequests::class);
Event::listen('igniter.user.beforeThrottleRequest', function ($request, $params) {
$handler = str_after($request->header('x-igniter-request-handler'), '::');
if (in_array($handler, [
'onLogin',
'onRegister',
'onActivate',
'onForgotPassword',
'onResetPassword',
])) {
$params->maxAttempts = 6;
$params->decayMinutes = 1;
return true;
}
});
}
}