File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -223,20 +223,6 @@ class Auth extends BaseConfig
223223 'username ' ,
224224 ];
225225
226- /**
227- * --------------------------------------------------------------------
228- * Validation Rules for username
229- * --------------------------------------------------------------------
230- *
231- * @var string[]
232- */
233- public array $ validationRulesUsername = [
234- 'required ' ,
235- 'max_length[30] ' ,
236- 'min_length[3] ' ,
237- 'regex_match[/\A[a-zA-Z0-9\.]+\z/] ' ,
238- ];
239-
240226 /**
241227 * --------------------------------------------------------------------
242228 * Additional Fields for "Nothing Personal"
Original file line number Diff line number Diff line change @@ -64,12 +64,27 @@ public function loginAction(): RedirectResponse
6464 protected function getValidationRules (): array
6565 {
6666 return setting ('Validation.login ' ) ?? [
67- //'username' => setting('Auth.validationRulesUsername' ),
67+ //'username' => setting('Validation._username') ?? $this->getUsernameRules( ),
6868 'email ' => 'required|max_length[254]|valid_email ' ,
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+
7388 /**
7489 * Logs the current user out.
7590 */
Original file line number Diff line number Diff line change @@ -130,13 +130,15 @@ protected function getUserEntity(): User
130130 */
131131 protected function getValidationRules (): array
132132 {
133- $ usernameRules = array_merge (
134- setting ('Auth.validationRulesUsername ' ),
133+ $ usernameRules = setting ('Validation._username ' ) ?? LoginController::getUsernameRules ();
134+
135+ $ registrationUsernameRules = array_merge (
136+ $ usernameRules ,
135137 ['is_unique[users.username] ' ]
136138 );
137139
138140 return setting ('Validation.registration ' ) ?? [
139- 'username ' => $ usernameRules ,
141+ 'username ' => $ registrationUsernameRules ,
140142 'email ' => 'required|valid_email|is_unique[auth_identities.secret] ' ,
141143 'password ' => 'required|strong_password ' ,
142144 'password_confirm ' => 'required|matches[password] ' ,
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 ;
89use CodeIgniter \Test \DatabaseTestTrait ;
910use CodeIgniter \Test \FeatureTestTrait ;
1011use Config \Services ;
@@ -123,7 +124,7 @@ public function testLoginActionUsernameSuccess(): void
123124 'password ' => 'required ' ,
124125 ];
125126 };
126- $ config ->login ['username ' ] = setting ( ' Auth.validationRulesUsername ' );
127+ $ config ->login ['username ' ] = LoginController:: getUsernameRules ( );
127128 Factories::injectMock ('config ' , 'Validation ' , $ config );
128129
129130 $ this ->user ->createEmailIdentity ([
You can’t perform that action at this time.
0 commit comments