inc/classes/exceptions/main/class_InvalidCommandException.php -text
inc/classes/exceptions/main/class_InvalidCommandInstanceException.php -text
inc/classes/exceptions/main/class_InvalidControllerException.php -text
+inc/classes/exceptions/main/class_InvalidInterfaceException.php -text
inc/classes/exceptions/main/class_InvalidObjectException.php -text
inc/classes/exceptions/main/class_MissingArrayElementsException.php -text
inc/classes/exceptions/main/class_MissingDecimalsThousandsSeperatorException.php -text
// CFG: LOGIN-USER-STATUS-URL
$cfg->setConfigEntry('login_user_status_url', "index.php?app=ship-simu&page=login_area&action=status_problem");
-// CFG: LOGIN-USER-UNCONFIRMED-URL
-$cfg->setConfigEntry('login_user_unconfirmed_url', "index.php?app=ship-simu&page=status_unconfirmed_problem");
+// CFG: USER-NOT-UNCONFIRMED-URL
+$cfg->setConfigEntry('user_not_unconfirmed_url', "index.php?app=ship-simu&page=status&status=unconfirmed_problem");
+
+// CFG: USER-UNCONFIRMED-EMAIL-MISSING-URL
+$cfg->setConfigEntry('user_unconfirmed_email_missing_url', "index.php?app=ship-simu&page=status&status=unconfirmed_email_missing");
// CFG: LOGIN-DEFAULT-ACTION
$cfg->setConfigEntry('login_default_action', "welcome");
--- /dev/null
+<?php
+/**
+ * An exception thrown when an class instance does not implement a given interface
+ *
+ * @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 InvalidInterfaceException extends FrameworkException {
+ /**
+ * The constructor
+ *
+ * @param $classArray Array with exception data
+ * @param $code Code number for the exception
+ * @return void
+ */
+ public function __construct (array $classArray, $code) {
+ // Add a message around the missing class
+ $message = sprintf("[%s:%d] Object does not implement expected interface <span id=\"exception_reason\">.",
+ $classArray[0]->__toString(),
+ $this->getLine(),
+ $classArray[1]
+ );
+
+ // Call parent constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
*/
public function __construct (FrameworkInterface $class, $code) {
// Add a message around the missing class
- $message = sprintf("[%s:%d] Objects are not allowed here. (Object: <span id=\"exception_reason\">%s</span>)",
+ $message = sprintf("[%s:%d] Objects of type <span id=\"exception_reason\">%s</span> are not allowed here.",
$class->__toString(),
$this->getLine(),
$class->getObjectDescription()
* @param $requestInstance An instance of a class with an Requestable interface
* @param $responseInstance An instance of a class with an Responseable interface
* @return void
+ * @throws InvalidInterfaceException If the user class does not implement ManageableUser
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
+ // Get user instance from registry
+ $userInstance = Registry::getRegistry()->getInstance('user');
+
+ // Does the user instance implement ManageableUser?
+ if (!$userInstance instanceof ManageableUser) {
+ // Throw exception here
+ throw new InvalidInterfaceException(array($userInstance, 'ManageableUser'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
+ } // END - if
+
// Get template instance
$templateInstance = $responseInstance->getTemplateInstance();
// Assign base URL
$templateInstance->assignConfigVariable('base_url');
+ // Get a RNG instance (Random Number Generator)
+ $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+
+ // Generate a pseudo-random string
+ $randomString = $rngInstance->randomString(255);
+
+ // Get a crypto instance
+ $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+
+ // Hash and encrypt the string
+ $hashedString = $cryptoInstance->hashString($cryptoInstance->encryptString($randomString));
+
+ // Update the user class
+ $userInstance->updateDatabaseField('confirm_hash', $hashedString);
+
// Get a mailer class
$mailerInstance = ObjectFactory::createObjectByConfiguredName('mailer_class', array($templateInstance));
$authInstance->updateAuthData();
// Write all updates to the database
- $userInstance->flushUpdates();
+ $userInstance->flushPendingUpdates();
}
}
// Get a user instance for comparison
$userInstance = User::createUserByRequest($requestInstance);
+ // Is the email address valid?
+ if (!$userInstance->ifEmailAddressExists()) {
+ // Request is invalid!
+ $requestInstance->requestIsValid(false);
+
+ // Redirect to configured URL
+ $responseInstance->redirectToConfiguredUrl('user_unconfirmed_email_missing_url');
+
+ // Stop processing here
+ exit();
+ } // END - if
+
// Is the user account confirmed?
if ($userInstance->getField('user_status') != $this->getConfigInstance()->readConfig('user_status_unconfirmed')) {
// Request is invalid!
$requestInstance->requestIsValid(false);
// Redirect to configured URL
- $responseInstance->redirectToConfiguredUrl('login_user_unconfirmed_url');
+ $responseInstance->redirectToConfiguredUrl('user_not_unconfirmed_url');
// Stop processing here
exit();
if ($this->getResultInstance()->next()) {
// Entry found
$exists = true;
+
+ // Is the username set?
+ if ($this->getUserName() == "") {
+ // Get current entry
+ $currEntry = $this->getResultInstance()->current();
+
+ // Set the username
+ $this->setUserName($currEntry['username']);
+ } // END - if
} // END - if
// Return the status
*
* @param $fieldName Field name which we shall get
* @return $fieldValue Field value from the user
- * @todo Do we need to secure this here against missing results?
+ * @throws NullPointerException If the result instance is null
*/
public final function getField ($fieldName) {
// Default field value
$fieldValue = null;
+ // Get result instance
+ $resultInstance = $this->getResultInstance();
+
+ // Is this instance null?
+ if (is_null($resultInstance)) {
+ // Then the user instance is no longer valid (expired cookies?)
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ } // END - if
+
// Get current array
- $fieldArray = $this->getResultInstance()->current();
+ $fieldArray = $resultInstance->current();
// Does the field exist?
if (isset($fieldArray[$fieldName])) {
/**
* Updates the last activity timestamp and last performed action in the
- * database result. You should call flushUpdates() to flush these updates
+ * database result. You should call flushPendingUpdates() to flush these updates
* to the database layer.
*
* @param $requestInstance A requestable class instance
}
/**
- * Flushs all updated entries to the database layer
+ * Flushs all pending updates to the database layer
*
* @return void
*/
- public function flushUpdates () {
+ public function flushPendingUpdates () {
// No updates will be flushed to database!
}
}
$this->generateUniqueId();
}
+ /**
+ * Destructor to always flush updates
+ *
+ * @return void
+ */
+ public function __destruct () {
+ // Flush any updated entries to the database
+ $this->flushPendingUpdates();
+
+ // Call parent destructor
+ parent::__destruct();
+ }
+
/**
* Creates an instance of this user class by a provided username. This
* factory method will check if the username is already taken and if not
/**
* Updates the last activity timestamp and last performed action in the
- * database result. You should call flushUpdates() to flush these updates
+ * database result. You should call flushPendingUpdates() to flush these updates
* to the database layer.
*
* @param $requestInstance A requestable class instance
}
/**
- * Flushs all updated entries to the database layer
+ * Updates a given field with new value
*
+ * @param $fieldName Field to update
+ * @param $fieldValue New value to store
* @return void
*/
- public function flushUpdates () {
- // Get a database wrapper
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+ public function updateDatabaseField ($fieldName, $fieldValue) {
+ // Get a critieria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add search criteria
+ $searchInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $searchInstance->setLimit(1);
+
+ // Now get another criteria
+ $updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
+
+ // And add our both entries
+ $updateInstance->addCriteria($fieldName, $fieldValue);
+
+ // Add the search criteria for searching for the right entry
+ $updateInstance->setSearchInstance($searchInstance);
+ // Remember the update in database result
+ $this->getResultInstance()->add2UpdateQueue($updateInstance);
+ }
+
+ /**
+ * Flushs all pending updates to the database layer
+ *
+ * @return void
+ */
+ public function flushPendingUpdates () {
// Do we have data to update?
if ($this->getResultInstance()->ifDataNeedsFlush()) {
+ // Get a database wrapper
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class');
+
// Yes, then send the whole result to the database layer
$wrapperInstance->doUpdateByResult($this->getResultInstance());
} // END - if