]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
More class descriptions translated, generic user class added
[shipsimu.git] / inc / classes / main / filter / validator / class_UserNameValidatorFilter.php
index 6f18e6b5ebd47f6e3f6fbd9f021381d1b6a31eb9..1c7c54afc820da98a0e2332fafd82737f416aa5a 100644 (file)
@@ -88,16 +88,7 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
 
                        // 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)) {
+               } elseif ($this->ifUserNameIsTaken($userName)) {
                        // Username is already taken
                        $requestInstance->requestIsValid(false);
 
@@ -108,6 +99,32 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                        return false;
                }
        }
+
+       /**
+        * Check wether the username as already been taken
+        *
+        * @param       $userName               Username to check for existence
+        * @return      $alreadyTaken   Wether the username has been taken
+        */
+       private function ifUserNameIsTaken ($userName) {
+               // Default is already taken
+               $alreadyTaken = true;
+
+               // Try to create a user instance
+               try {
+                       // If this instance is created then the username *does* exist
+                       $userInstance = User::createUserByUsername($userName);
+               } catch (UsernameMissingException $e) {
+                       // Okay, this user is missing!
+                       $alreadyTaken = false;
+               } catch (FrameworkException $e) {
+                       // Something bad happend
+                       ApplicationEntryPoint::app_die(sprintf("Exception: %s", $e->__toString()));
+               }
+
+               // Return the result
+               return $alreadyTaken;
+       }
 }
 
 // [EOF]