// 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);
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]