<?php
/**
* A concrete filter for validating the email address. This filter may intercept
- * the filter chain if no email address is given or if the supplied username has
- * an invalid form. It could also intercept the filter chain if the email
- * address is already used by some one if configuration requires this.
+ * the filter chain if no email address is given or if the supplied email has an
+ * invalid form. It could also intercept the filter chain if the email address
+ * is already used by some one if configuration requires this.
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
*/
class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable {
/**
- * Private constructor
+ * Protected constructor
*
* @return void
*/
// Add a message to the response
$responseInstance->addFatalMessage('email_taken');
+ // Abort here
+ return false;
+ } elseif ($email1 != $email2) {
+ // Emails didn't match
+ $requestInstance->requestIsValid(false);
+
+ // Add a message to the response
+ $responseInstance->addFatalMessage('emails_mismatch');
+
// Abort here
return false;
} // END - elseif
/**
* Check wether the email as already been taken
*
- * @param $email Email to check for existence
+ * @param $email Email to check for existence
* @return $alreadyTaken Wether the email has been taken
*/
private function ifEmailIsTaken ($email) {
// Default is already taken
$alreadyTaken = true;
- $this->partialStub(sprintf("Email: %s", $email));
+
+ // Initialize instance
+ $userInstance = null;
+
+ // Get a registry instance
+ $registry = Registry::getRegistry();
+
+ // Is the user already there?
+ if ($registry->instanceExists('user')) {
+ // Use the instance for checking for the email
+ $userInstance = $registry->getInstance('user');
+ $userInstance->setEmailAddress($email);
+ } else {
+ // If this instance is created then the username *does* exist
+ $userInstance = User::createUserByEmail($email);
+
+ // Remember this user instance in our registry for later usage
+ $registry->addInstance('user', $userInstance);
+ }
+
+ // Does the email exist?
+ if (!$userInstance->ifEmailAddressExists()) {
+ // This email has not being used yet
+ $alreadyTaken = false;
+ }
// Return the result
return $alreadyTaken;