* @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;
+ }
}
}