Skip to content

Commit b66bce7

Browse files
committed
refactor: extract method
1 parent 3f365a7 commit b66bce7

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/Controllers/RegisterController.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodeIgniter\Config\Factories;
77
use CodeIgniter\Events\Events;
88
use CodeIgniter\HTTP\RedirectResponse;
9+
use CodeIgniter\Shield\Authentication\Actions\ActionInterface;
910
use CodeIgniter\Shield\Authentication\Authenticators\Session;
1011
use CodeIgniter\Shield\Entities\User;
1112
use CodeIgniter\Shield\Models\UserModel;
@@ -89,15 +90,8 @@ public function registerAction(): RedirectResponse
8990

9091
// If an action has been defined for login, start it up.
9192
$actionClass = setting('Auth.actions')['register'] ?? null;
92-
9393
if (! empty($actionClass)) {
94-
$action = Factories::actions($actionClass); // @phpstan-ignore-line
95-
96-
if (method_exists($action, 'afterRegister')) {
97-
$action->afterRegister($user);
98-
}
99-
100-
session()->set('auth_action', $actionClass);
94+
$this->startUpAction($actionClass, $user);
10195

10296
return redirect()->to('auth/a/show');
10397
}
@@ -113,6 +107,23 @@ public function registerAction(): RedirectResponse
113107
->with('message', lang('Auth.registerSuccess'));
114108
}
115109

110+
/**
111+
* @param class-string<ActionInterface> $actionClass
112+
*/
113+
private function startUpAction(string $actionClass, User $user)
114+
{
115+
// @TODO I want to move this logic to Authenticators\Session,
116+
// and create register() method in Authenticators\Session.
117+
118+
$action = Factories::actions($actionClass); // @phpstan-ignore-line
119+
120+
if (method_exists($action, 'afterRegister')) {
121+
$action->afterRegister($user);
122+
}
123+
124+
session()->set('auth_action', $actionClass);
125+
}
126+
116127
/**
117128
* Returns the User provider
118129
*/

0 commit comments

Comments
 (0)