]> git.mxchange.org Git - shipsimu.git/commitdiff
Username filter begun with basic checks
authorRoland Häder <roland@mxchange.org>
Tue, 27 May 2008 21:22:00 +0000 (21:22 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 27 May 2008 21:22:00 +0000 (21:22 +0000)
inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
inc/classes/main/request/class_HttpRequest.php

index efc3fecafeee65730e90d983803a77f9b5f15ba3..9ec225165648d120cc765c2c66b7b85212b51fc8 100644 (file)
@@ -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;
+               }
        }
 }
 
index 6826d76b71dbdeea91a4774103c4c03e65341252..133f08af01be22137aa36049f467040b695bf785 100644 (file)
@@ -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]