Skip to content

Commit d1c0658

Browse files
committed
refactor: move validation rules to ValidationRules
1 parent 82fe260 commit d1c0658

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/Controllers/LoginController.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use App\Controllers\BaseController;
88
use CodeIgniter\HTTP\RedirectResponse;
99
use CodeIgniter\Shield\Authentication\Authenticators\Session;
10-
use CodeIgniter\Shield\Authentication\Passwords;
1110
use CodeIgniter\Shield\Traits\Viewable;
11+
use CodeIgniter\Shield\Validation\ValidationRules;
1212

1313
class LoginController extends BaseController
1414
{
@@ -82,17 +82,9 @@ public function loginAction(): RedirectResponse
8282
*/
8383
protected function getValidationRules(): array
8484
{
85-
return setting('Validation.login') ?? [
86-
// 'username' => config('Auth')->usernameValidationRules,
87-
'email' => config('Auth')->emailValidationRules,
88-
'password' => [
89-
'label' => 'Auth.password',
90-
'rules' => 'required|' . Passwords::getMaxLengthRule(),
91-
'errors' => [
92-
'max_byte' => 'Auth.errorPasswordTooLongBytes',
93-
],
94-
],
95-
];
85+
$rules = new ValidationRules();
86+
87+
return $rules->getLoginRules();
9688
}
9789

9890
/**

src/Validation/ValidationRules.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ public function getRegistrationRules(): array
4949
];
5050
}
5151

52+
public function getLoginRules(): array
53+
{
54+
helper('setting');
55+
56+
return setting('Validation.login') ?? [
57+
// 'username' => $this->config->usernameValidationRules,
58+
'email' => $this->config->emailValidationRules,
59+
'password' => $this->getPasswordRules(),
60+
];
61+
}
62+
5263
public function getPasswordRules(): array
5364
{
5465
return [

0 commit comments

Comments
 (0)