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,6 +223,20 @@ 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+
226240 /**
227241 * --------------------------------------------------------------------
228242 * Additional Fields for "Nothing Personal"
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ public function loginAction(): RedirectResponse
6464 protected function getValidationRules (): array
6565 {
6666 return setting ('Validation.login ' ) ?? [
67- //'username' => 'required|max_length[30]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|min_length[3]' ,
67+ //'username' => setting('Auth.validationRulesUsername') ,
6868 'email ' => 'required|max_length[254]|valid_email ' ,
6969 'password ' => 'required ' ,
7070 ];
Original file line number Diff line number Diff line change @@ -130,8 +130,13 @@ protected function getUserEntity(): User
130130 */
131131 protected function getValidationRules (): array
132132 {
133+ $ usernameRules = array_merge (
134+ setting ('Auth.validationRulesUsername ' ),
135+ ['is_unique[users.username] ' ]
136+ );
137+
133138 return setting ('Validation.registration ' ) ?? [
134- 'username ' => ' required|max_length[30]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|min_length[3]|is_unique[users.username] ' ,
139+ 'username ' => $ usernameRules ,
135140 'email ' => 'required|valid_email|is_unique[auth_identities.secret] ' ,
136141 'password ' => 'required|strong_password ' ,
137142 'password_confirm ' => 'required|matches[password] ' ,
Original file line number Diff line number Diff line change @@ -120,10 +120,10 @@ public function testLoginActionUsernameSuccess(): void
120120 // Change the validation rules
121121 $ config = new class () extends Validation {
122122 public $ login = [
123- 'username ' => 'required|max_length[30]|regex_match[/\A[a-zA-Z0-9\.]+\z/]|min_length[3] ' ,
124123 'password ' => 'required ' ,
125124 ];
126125 };
126+ $ config ->login ['username ' ] = setting ('Auth.validationRulesUsername ' );
127127 Factories::injectMock ('config ' , 'Validation ' , $ config );
128128
129129 $ this ->user ->createEmailIdentity ([
You can’t perform that action at this time.
0 commit comments