From 0b50907763979db50e24304d60bb507e3c2df790 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 27 May 2008 21:22:00 +0000 Subject: [PATCH] Username filter begun with basic checks --- .../class_UserNameValidatorFilter.php | 43 ++++++++++++++++++- .../main/request/class_HttpRequest.php | 9 ++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index efc3fec..9ec2251 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -66,8 +66,47 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable * @return void */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // Implement this! - $this->partialStub("Please implement this method."); + // Get username from request + $userName = $requestInstance->getRequestElement("username"); + + // Is the username set? + if (is_null($userName)) { + // Not found in form so stop the filtering process + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_unset'); + + // Abort here + return false; + } elseif (empty($userName)) { + // Empty field! + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_empty'); + + // Abort here + return false; + } elseif (!$this->ifUserNameIsValid($userName)) { + // Regular expression check failed! + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_invalid'); + + // Abort here + return false; + } elseif (!$this->ifUserNameIsTaken($userName)) { + // Username is already taken + $requestInstance->requestIsValid(false); + + // Set a message for the response + $responseInstance->addFatalMessage('username_taken'); + + // Abort here + return false; + } } } diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index 6826d76..133f08a 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -145,6 +145,15 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Return the value return $headerValue; } + + /** + * Getter for request method. This getter might be useful for security filters + * + * @return $requestMethod Used request method + */ + public final function getRequestMethod () { + return $_SERVER['REQUEST_METHOD']; + } } // [EOF] -- 2.39.5