From faffb29388d6b55cb104beb6e681e5c409f2891d Mon Sep 17 00:00:00 2001 From: ghost Date: Tue, 20 Feb 2024 00:58:10 +0200 Subject: [PATCH] add username regex config --- .env | 3 +++ config/services.yaml | 1 + src/Controller/UserController.php | 10 +++++----- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 4365b60..da241c1 100644 --- a/.env +++ b/.env @@ -74,6 +74,9 @@ APP_SESSION_ONLINE_TIMEOUT=900 # Moderators IP with extra permissions, separated with | APP_MODERATOR_REMOTE_IP= +# Username regex rule (must be compatible with APP_ADD_POST_KEY_REGEX) +APP_ADD_USER_NAME_REGEX=/^[A-z0-9-_]{1,64}$/ + # User name reserved (case insensitive) separated with | APP_ADD_USER_NAME_BLACKLIST=KevaChat|admin|moderator|test diff --git a/config/services.yaml b/config/services.yaml index 4a82d67..d37cadf 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -26,6 +26,7 @@ parameters: app.kevacoin.mine.solo.url: '%env(APP_KEVACOIN_MINE_SOLO_URL)%' app.session.default.timeout: '%env(APP_SESSION_DEFAULT_TIMEOUT)%' app.session.online.timeout: '%env(APP_SESSION_ONLINE_TIMEOUT)%' + app.add.user.name.regex: '%env(APP_ADD_USER_NAME_REGEX)%' app.add.user.name.blacklist: '%env(APP_ADD_USER_NAME_BLACKLIST)%' app.add.user.remote.ip.delay: '%env(APP_ADD_USER_REMOTE_IP_DELAY)%' app.add.room.remote.ip.regex: '%env(APP_ADD_ROOM_REMOTE_IP_REGEX)%' diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 1132c58..89cca9f 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -91,7 +91,7 @@ class UserController extends AbstractController } // Validate username regex - if (!preg_match($this->getParameter('app.add.post.key.regex'), $user['key'])) + if (!preg_match($this->getParameter('app.add.user.name.regex'), $user['key'])) { continue; } @@ -470,7 +470,7 @@ class UserController extends AbstractController } // Validate username regex - if (!preg_match($this->getParameter('app.add.post.key.regex'), $username)) + if (!preg_match($this->getParameter('app.add.user.name.regex'), $username)) { return $this->redirectToRoute( 'user_add', @@ -478,7 +478,7 @@ class UserController extends AbstractController 'username' => $request->get('username'), 'error' => sprintf( $translator->trans('Username does not match node requirements: %s!'), - $this->getParameter('app.add.post.key.regex') + $this->getParameter('app.add.user.name.regex') ) ] ); @@ -798,7 +798,7 @@ class UserController extends AbstractController } // Validate username regex - if (!preg_match($this->getParameter('app.add.post.key.regex'), $username)) + if (!preg_match($this->getParameter('app.add.user.name.regex'), $username)) { return $this->redirectToRoute( 'user_login', @@ -806,7 +806,7 @@ class UserController extends AbstractController 'username' => $request->get('username'), 'error' => sprintf( $translator->trans('Username does not match node requirements: %s!'), - $this->getParameter('app.add.post.key.regex') + $this->getParameter('app.add.user.name.regex') ) ] );