File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace CodeIgniter \Shield \Config ;
4+
5+ use CodeIgniter \Config \BaseConfig ;
6+
7+ /**
8+ * Config for Session Authenticator
9+ */
10+ class AuthSession extends BaseConfig
11+ {
12+ /**
13+ * The validation rules for username
14+ *
15+ * @var string[]
16+ */
17+ public array $ usernameValidationRules = [
18+ 'required ' ,
19+ 'max_length[30] ' ,
20+ 'min_length[3] ' ,
21+ 'regex_match[/\A[a-zA-Z0-9\.]+\z/] ' ,
22+ ];
23+
24+ /**
25+ * The validation rules for email
26+ *
27+ * @var string[]
28+ */
29+ public array $ emailValidationRules = [
30+ 'required ' ,
31+ 'max_length[254] ' ,
32+ 'valid_email ' ,
33+ ];
34+ }
Original file line number Diff line number Diff line change @@ -64,41 +64,12 @@ public function loginAction(): RedirectResponse
6464 protected function getValidationRules (): array
6565 {
6666 return setting ('Validation.login ' ) ?? [
67- //'username' => static::getUsernameRules() ,
68- 'email ' => static :: getEmailRules () ,
67+ //'username' => config('AuthSession')->usernameValidationRules ,
68+ 'email ' => config ( ' AuthSession ' )-> emailValidationRules ,
6969 'password ' => 'required ' ,
7070 ];
7171 }
7272
73- /**
74- * Returns the validation rules for username
75- *
76- * @return string[]
77- */
78- public static function getUsernameRules (): array
79- {
80- return [
81- 'required ' ,
82- 'max_length[30] ' ,
83- 'min_length[3] ' ,
84- 'regex_match[/\A[a-zA-Z0-9\.]+\z/] ' ,
85- ];
86- }
87-
88- /**
89- * Returns the validation rules for email
90- *
91- * @return string[]
92- */
93- public static function getEmailRules (): array
94- {
95- return [
96- 'required ' ,
97- 'max_length[254] ' ,
98- 'valid_email ' ,
99- ];
100- }
101-
10273 /**
10374 * Logs the current user out.
10475 */
Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ private function recordLoginAttempt(
191191 protected function getValidationRules (): array
192192 {
193193 return [
194- 'email ' => LoginController:: getEmailRules () ,
194+ 'email ' => config ( ' AuthSession ' )-> emailValidationRules ,
195195 ];
196196 }
197197}
Original file line number Diff line number Diff line change @@ -131,11 +131,11 @@ protected function getUserEntity(): User
131131 protected function getValidationRules (): array
132132 {
133133 $ registrationUsernameRules = array_merge (
134- LoginController:: getUsernameRules () ,
134+ config ( ' AuthSession ' )-> usernameValidationRules ,
135135 ['is_unique[users.username] ' ]
136136 );
137137 $ registrationEmailRules = array_merge (
138- LoginController:: getEmailRules () ,
138+ config ( ' AuthSession ' )-> emailValidationRules ,
139139 ['is_unique[auth_identities.secret] ' ]
140140 );
141141
Original file line number Diff line number Diff line change 55use CodeIgniter \Config \Factories ;
66use CodeIgniter \I18n \Time ;
77use CodeIgniter \Shield \Authentication \Actions \Email2FA ;
8- use CodeIgniter \Shield \Controllers \LoginController ;
98use CodeIgniter \Test \DatabaseTestTrait ;
109use CodeIgniter \Test \FeatureTestTrait ;
1110use Config \Services ;
@@ -124,7 +123,7 @@ public function testLoginActionUsernameSuccess(): void
124123 'password ' => 'required ' ,
125124 ];
126125 };
127- $ config ->login ['username ' ] = LoginController:: getUsernameRules () ;
126+ $ config ->login ['username ' ] = config ( ' AuthSession ' )-> usernameValidationRules ;
128127 Factories::injectMock ('config ' , 'Validation ' , $ config );
129128
130129 $ this ->user ->createEmailIdentity ([
You can’t perform that action at this time.
0 commit comments