Skip to content

Commit 7c98cbc

Browse files
authored
Merge branch 'main' into feature/rainlab-support
2 parents 3ca2bfd + a59aca7 commit 7c98cbc

12 files changed

+98
-273
lines changed

Plugin.php

+18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function pluginDetails()
5454
*/
5555
public function register()
5656
{
57+
$this->checkRequiredPlugins();
58+
5759
$this->app->singleton(
5860
UserPluginResolverContract::class,
5961
static fn() => UserPluginResolver::instance(),
@@ -83,6 +85,22 @@ public function boot()
8385
$this->addEventListeners();
8486
}
8587

88+
protected function checkRequiredPlugins()
89+
{
90+
$plugins = ['RainLab.User', 'Lovata.Buddies'];
91+
$pluginInstalled = false;
92+
93+
foreach ($plugins as $pluginName) {
94+
if (PluginManager::instance()->hasPlugin($pluginName)) {
95+
$pluginInstalled = true;
96+
}
97+
}
98+
99+
if (!$pluginInstalled) {
100+
PluginManager::instance()->disablePlugin('ReaZzon.JWTAuth');
101+
}
102+
}
103+
86104
/**
87105
*
88106
*/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Route::group(['middleware' => [\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::cl
3535
or
3636

3737
```php
38-
Route::post('account', function () {
38+
Route::get('account', function () {
3939

4040
// Logic that should be available only for authenticated users
4141

classes/contracts/Plugin.php

+4
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ public function registrationValidationExtend(): array;
3838
* @return array
3939
*/
4040
public function loginValidationExtend(): array;
41+
42+
public function initActivation($model): string;
43+
44+
public function activateByCode($code);
4145
}

classes/contracts/UserPluginResolver.php

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ interface UserPluginResolver
1818
*/
1919
public function getModel(): string;
2020

21+
public function getResolver(): Plugin;
22+
2123
/**
2224
* @return Plugin
2325
*/

classes/middlewares/ResolveUser.php

-44
This file was deleted.

classes/resolvers/BuddiesPlugin.php

+61
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,65 @@ public function getJWTCustomClaims()
140140
}
141141
};
142142
}
143+
144+
/**
145+
* @param User $user
146+
* @return string
147+
*/
148+
public function initActivation($user): string
149+
{
150+
$activationType = BuddiesSettings::get('activation_type', 'off');
151+
152+
switch ($activationType) {
153+
case 'on':
154+
$user->activation_code = $user->getActivationCode();
155+
$user->is_activated = true;
156+
break;
157+
158+
case 'off':
159+
$user->activation_code = $user->getActivationCode();
160+
$user->is_activated = false;
161+
break;
162+
163+
case 'mail':
164+
$user->activation_code = $user->getActivationCode();
165+
$user->is_activated = false;
166+
167+
//Get mail data
168+
$mailData = [
169+
'user' => $user,
170+
'user_item' => UserItem::make($user->id, $this),
171+
'site_url' => config('app.url'),
172+
];
173+
174+
$templateName = Settings::getValue('registration_mail_template', 'lovata.buddies::mail.registration');
175+
176+
$sendMailHelper = SendMailHelper::instance();
177+
$sendMailHelper->send(
178+
$templateName,
179+
$user->email,
180+
$mailData,
181+
Registration::EMAIL_TEMPLATE_DATA_EVENT,
182+
true);
183+
184+
break;
185+
}
186+
187+
$user->forceSave();
188+
189+
return $activationType;
190+
}
191+
192+
public function activateByCode($code)
193+
{
194+
$user = User::getByActivationCode($code)->first();
195+
if (empty($user)) {
196+
return null;
197+
}
198+
199+
$user->activate();
200+
$user->forceSave();
201+
202+
return $user;
203+
}
143204
}

classes/resolvers/RainlabPlugin.php

+10
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,14 @@ public function afterRegistrationActivate()
7474
}
7575
};
7676
}
77+
78+
public function initActivation($model): string
79+
{
80+
// TODO: Implement initActivation() method.
81+
}
82+
83+
public function activateByCode($code)
84+
{
85+
// TODO: Implement activateByCode() method.
86+
}
7787
}

config/jwtauth.php

-16
This file was deleted.

controllers/Authentication.php

-100
This file was deleted.

http/controllers/AuthController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AuthController extends Controller
2020
* @return array
2121
* @throws \ApplicationException
2222
*/
23-
public function __invoke(LoginRequest $loginRequest): TokenResource
23+
public function __invoke(LoginRequest $loginRequest): array
2424
{
2525
/** @var JWTSubject $user */
2626
$user = $this->userPluginResolver

http/controllers/RefreshController.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
use October\Rain\Argon\Argon;
77
use ReaZzon\JWTAuth\Classes\Dto\TokenDto;
8-
use ReaZzon\JWTAuth\Http\Resources\TokenResource;
98

109
/**
1110
*
@@ -15,7 +14,7 @@ class RefreshController extends Controller
1514
/**
1615
* @return array
1716
*/
18-
public function __invoke(): TokenResource
17+
public function __invoke(): array
1918
{
2019
$tokenRefreshed = $this->userPluginResolver->getGuard()->refresh(true);
2120
$this->userPluginResolver->getGuard()->setToken($tokenRefreshed);

0 commit comments

Comments
 (0)