inc/classes/exceptions/template/class_UnsupportedTemplateEngineException.php -text
inc/classes/exceptions/template/class_ViewHelperNotFoundException.php -text
inc/classes/exceptions/user/.htaccess -text
+inc/classes/exceptions/user/class_UserEmailMissingException.php -text
inc/classes/exceptions/user/class_UsernameMissingException.php -text
inc/classes/interfaces/.htaccess -text
inc/classes/interfaces/application/.htaccess -text
*
* @param $requestInstance An instance of a Requestable class
* @return void
+ * @throws UserLoginMethodException If wether username nor email login
+ * was detected
+ * @throws MissingMethodException If a method was not found in the
+ * User class
+ * @throws UserEmailMissingException If user with given email address was
+ * not found in database
*/
public function doLogin (Requestable $requestInstance) {
- $this->partialStub();
+ // By default no method is selected
+ $method = null;
+ $data = "";
+
+ // Detect login method (username or email) and try to get a userinstance
+ if (!is_null($requestInstance->getRequestElement('username'))) {
+ // Username found!
+ $method = "createUserByUsername";
+ $data = $requestInstance->getRequestElement('username');
+ } elseif (!is_null($requestInstance->getRequestElement('email'))) {
+ // Email found!
+ $method = "createUserByEmail";
+ $data = $requestInstance->getRequestElement('email');
+ }
+
+ // Is a method detected?
+ if (is_null($method)) {
+ // Then abort here
+ throw new UserLoginMethodException($this, self::EXCEPTION_MISSING_METHOD);
+ } elseif (!method_exists("User", $method)) {
+ // The method is invalid!
+ throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD);
+ }
+
+ // Get a instance of the registry
+ $userInstance = Registry::getRegistry()->getInstance('user');
+
+ // Is there an instance?
+ if (is_null($userInstance)) {
+ // Get a user instance
+ $userInstance = call_user_func_array(array("User", $method), array($data));
+ } // END - if
+
+ // If we have email login then check if a user account with that email exists!
+ if (($method == "createUserByEmail") && (!$userInstance->ifEmailAddressExists())) {
+ // The user account is missing!
+ throw new UserEmailMissingException(array($this, $data), User::EXCEPTION_USER_EMAIL_NOT_FOUND);
+ } // END - if
+
+ // Partially finished!
+ $this->partialStub("userInstance set, continue with password verification");
}
}
--- /dev/null
+<?php
+/**
+ * A class for non-existing user emails
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class UserEmailMissingException extends FrameworkException {
+ /**
+ * The super constructor for all exceptions
+ *
+ * @param $msgArray The non-optional message for the exception
+ * @param $code An optional code for better debugging
+ * @return void
+ */
+ public function __construct(array $msgArray, $code = 0) {
+ // Create the message
+ $message = sprintf("[%s:%d] User email <u>%s</u> was not found.",
+ $msgArray[0]->__toString(),
+ $this->getLine(),
+ $msgArray[1]
+ );
+
+ // Make sure everything is assigned properly
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
$this->getFileExtension()
);
- // Skip here while developing
- return true;
-
// Try to save the request away
try {
// Get a file pointer instance
if ($registry->instanceExists('user')) {
// Use the instance for checking for the email
$userInstance = $registry->getInstance('user');
+ $userInstance->setUserName($userName);
} else {
// If this instance is created then the username *does* exist
try {
+ // Get a new instance
$userInstance = User::createUserByUsername($userName);
// Remember this user instance in our registry for later usage
private $email = "";
// Exceptions
- const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
+ const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
+ const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01;
/**
* Protected constructor
$userInstance = new User();
// Set the username
- $userInstance->setUsername($userName);
+ $userInstance->setUserName($userName);
// Check if the username exists
if (!$userInstance->ifUsernameExists()) {
* @param $userName The username to set
* @return void
*/
- protected final function setUsername ($userName) {
- $this->UserName = $userName;
+ public final function setUserName ($userName) {
+ $this->userName = $userName;
}
/**
* browser or debug lines for a log file, etc. to the registered debug
* output instance.
*
+ * @param $outStream Data we shall "stream" out to the world
* @return void
*/
public final function output ($outStream) {