application/ship-simu/main/factories/class_ShipSimuWebNewsFactory.php -text
application/ship-simu/main/login/.htaccess -text
application/ship-simu/main/login/class_ShipSimuUserLogin.php -text
+application/ship-simu/main/login/helper/.htaccess -text
+application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php -text
application/ship-simu/main/parts/.htaccess -text
application/ship-simu/main/parts/class_BaseShipPart.php -text
application/ship-simu/main/parts/maschineroom/.htaccess -text
inc/classes/exceptions/helper/class_FormGroupClosedException.php -text
inc/classes/exceptions/helper/class_FormOpenedException.php -text
inc/classes/exceptions/helper/class_InvalidFormNameException.php -text
+inc/classes/exceptions/helper/class_UserInstanceMissingException.php -text
inc/classes/exceptions/io/.htaccess -text
inc/classes/exceptions/io/class_DirPointerNotOpenedException.php -text
inc/classes/exceptions/io/class_FilePointerNotOpenedException.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_UserPasswordMismatchException.php -text
inc/classes/exceptions/user/class_UsernameMissingException.php -text
inc/classes/interfaces/.htaccess -text
inc/classes/interfaces/application/.htaccess -text
inc/classes/interfaces/resolver/class_ControllerResolver.php -text
inc/classes/interfaces/response/.htaccess -text
inc/classes/interfaces/response/class_Responseable.php -text
+inc/classes/interfaces/result/.htaccess -text
+inc/classes/interfaces/result/class_SearchableResult.php -text
inc/classes/interfaces/template/.htaccess -text
inc/classes/interfaces/template/class_CompileableTemplate.php -text
inc/classes/interfaces/template/view/class_ViewHelper.php -text
inc/classes/main/helper/.htaccess -text
inc/classes/main/helper/class_ -text
inc/classes/main/helper/class_BaseHelper.php -text
+inc/classes/main/helper/login/.htaccess -text
+inc/classes/main/helper/login/class_BaseLoginHelper.php -text
inc/classes/main/helper/web/.htaccess -text
inc/classes/main/helper/web/class_WebFormHelper.php -text
inc/classes/main/io/.htaccess -text
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Is the application instance set?
-if (!isset($application)) {
- // We need this!
- ApplicationEntryPoint::app_die("[Main:] Interne Variable <strong>application</strong> nicht gefunden!");
-}
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
// Load all classes
-ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/", FrameworkConfiguration::getInstance()->readConfig('application_path'), $application));
+ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/", $cfg->readConfig('application_path'), $cfg->readConfig('app_name')));
// Clean up the global namespace
unset($lowerClasses);
// CFG: USER-STATUS-REGISTER
$cfg->setConfigEntry('user_status_register', "UNCONFIRMED");
+// CFG: LOGIN-HELPER
+$cfg->setConfigEntry('login_helper', "ShipSimuLoginHelper");
+
// [EOF]
?>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Is the application instance set?
-if (!isset($application)) {
- // We need this!
- ApplicationEntryPoint::app_die("[Main:] Interne Variable <strong>application</strong> nicht gefunden!");
-}
+// Get config instance
+$cfg = FrameworkConfiguration::getInstance();
// Load all classes for the application
foreach ($lowerClasses as $class) {
// Try to load the application classes
try {
- ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", FrameworkConfiguration::getInstance()->readConfig('application_path'), $application, $class));
+ ClassLoader::getInstance()->loadClasses(sprintf("%s/%s/%s", $cfg->readConfig('application_path'), $cfg->readConfig('app_name'), $class));
} catch (PathIsNoDirectoryException $e) {
ApplicationEntryPoint::app_die(sprintf("[Main:%s] Cannot find application classes in path <u>%s</u> for this reason: <u>%s</u>",
$application,
* 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
+ * @throws UserPasswordMismatchException If the supplied password did not
+ * match with the stored password
*/
public function doLogin (Requestable $requestInstance) {
// By default no method is selected
if (is_null($userInstance)) {
// Get a user instance
$userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('user_class'), $method), array($data));
+
+ // Remember this new instance in registry
+ Registry::getRegistry()->addInstance($userInstance);
} // 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);
+ // Is the password correct?
+ if (!$userInstance->ifPasswordHashMatches($requestInstance)) {
+ // Mismatching password
+ throw new UserPasswordMismatchException(array($this, $userInstance), User::EXCEPTION_USER_PASS_MISMATCH);
} // END - if
- // Partially finished!
- $this->partialStub("userInstance set, continue with password verification");
+ // Now do the real login. This can be cookie- or session-based login
+ // which depends on the admins setting then on the user's taste.
+ // 1) Get a login helper instance
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper', array($requestInstance));
+
+ // 2) Execute the login. This will now login...
+ $helperInstance->executeLogin();
}
}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A helper for Ship-Simu to login. This login helper first checks what setting
+ * (cookie or session) the admin has choosen then overwrites it with the setting
+ * from current user. The registry instance should hold an instance of this user
+ * class at key 'user' else an exception will be thrown. After this the setting
+ * from a login form will be taken as login method and be stored in database
+ * for later usage.
+ *
+ * The user shall be able to choose "Default login method" or similar to use his
+ * own login method.
+ *
+ * @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
+ * @todo Find an interface name for login helper
+ *
+ * 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 ShipSimuLoginHelper extends BaseLoginHelper {
+ // Exception constants
+ const EXCEPTION_INVALID_USER_INSTANCE = 0xf00;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set part description
+ $this->setObjectDescription("Login helper for Ship-Simu");
+
+ // Create unique ID number
+ $this->generateUniqueId();
+ }
+
+ /**
+ * Creates an instance of this class by given request instance
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $helperInstance An instance of this helper class
+ * @throws UserInstanceMissingException If the user instance in registry
+ * is missing or invalid
+ */
+ public final static function createShipSimuLoginHelper (Requestable $requestInstance) {
+ // Get a new instance first
+ $helperInstance = new ShipSimuLoginHelper();
+
+ // Get a user instance from registry
+ $userInstance = Registry::getRegistry()->getInstance('user');
+
+ // Is this instance valid?
+ if (!$userInstance instanceof ManageableUser) {
+ // Thrown an exception here
+ throw new UserInstanceMissingException (array($helperInstance, 'user'), self::EXCEPTION_INVALID_USER_INSTANCE);
+ } // END - if
+
+ // Get the login method from request
+ $methodRequest = $requestInstance->getRequestElement('login_method');
+
+ // Now, if that wents fine we can check if the request includes a login method entry
+ if ((!is_null($methodRequest)) && ($methodRequest != "default") && ($methodRequest != $userInstance->getLoginMethod())) {
+ // Okay, the login method has been choosen by user so remember it
+ $helperInstance->setLoginMethod($methodRequest);
+
+ // Remeber that we need to update the user account as well
+ $userInstance->addUpdateData('login_method', $methodRequest);
+ } elseif (($methodRequest == "default") && (is_string($userInstance->getLoginMethod()))) {
+ // Choose default method from user
+ $helperInstance->setLoginMethod($userInstance->getLoginMethod());
+ } else {
+ // Set default login method from config
+ $helperInstance->setDefaultLoginMethod();
+ }
+
+ // Return the prepared instance
+ return $helperInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * An exception thrown when a user instance is invalid
+ *
+ * @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 UserInstanceMissingException extends FrameworkException {
+ /**
+ * The constructor
+ *
+ * @param $classArray Array with class instance and registry key
+ * @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] Registry key <u>%s</u> does not include a class with implemented interface <u>ManageableUser</u>.",
+ $classArray[0]->__toString(),
+ $this->getLine(),
+ $classArray[1]
+ );
+
+ // Call parent constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A class for mismatching passwords
+ *
+ * @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 UserPasswordMismatchException 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] Supplied password for user <u>%s</u> did not match with stored password.",
+ $msgArray[0]->__toString(),
+ $this->getLine(),
+ $msgArray[1]->getUserName()
+ );
+
+ // Make sure everything is assigned properly
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
/**
* An interface for classes which are "able" to cache
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
*
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
* An interface for criterias
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
* An interface for local criterias
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-interface LocalCriteria extends Criteria {
+interface LocalSearchCriteria extends Criteria {
}
//
* @throws UnsupportedCriteriaException If the criteria is unsupported
* @throws SqlException If an SQL error occurs
*/
- function querySelect ($resultType, $tableName, Criteria $criteriaInstance);
+ function querySelect ($resultType, $tableName, LocalSearchCriteria $criteriaInstance);
/**
* "Inserts" a data set instance into a local file database folder
* @return void
* @throws SqlException If an SQL error occurs
*/
- function insertDataSet (StoreableCriteria $dataSetInstance);
+ function queryInsertDataSet (StoreableCriteria $dataSetInstance);
}
// [EOF]
/**
* An interface for user login classes
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
* A class for user registration
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
* An interface for registries
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
/**
* A class for registerable classes
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for searchable results
+ *
+ * @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/>.
+ */
+interface SearchableResult extends FrameworkInterface {
+ /**
+ * Searches for an entry in the data result and returns it
+ *
+ * @param $criteriaInstance The criteria to look inside the data set
+ * @return $result Found result entry
+ */
+ function searchEntry (LocalSearchCriteria $criteriaInstance);
+}
+
+// [EOF]
+?>
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface ManageableUser extends FrameworkInterface {
+ /**
+ * Determines wether the username exists or not
+ *
+ * @return $exists Wether the username exists
+ */
+ function ifUsernameExists ();
+
+ /**
+ * Determines wether the email exists or not
+ *
+ * @return $exists Wether the email exists
+ */
+ function ifEmailAddressExists ();
+
+ /**
+ * Checks if the supplied password hash in request matches with the stored
+ * in database.
+ *
+ * @param $requestInstance A requestable class instance
+ * @return $matches Wether the supplied password hash matches
+ */
+ function ifPasswordHashMatches (Requestable $requestInstance);
+
+ /**
+ * Adds data for later complete update
+ *
+ * @param $column Column we want to update
+ * @param $value New value to store in database
+ * @return void
+ */
+ function addUpdateData ($column, $value);
}
//
* A general action class
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* A simple memory cache (similar to a registry)
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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 file I/O instance for the template loader
*/
- private $fileIOInstance = null;
+ private $fileIoInstance = null;
/***********************
* Exception codes.... *
/**
* Private getter for file IO instance
*
- * @return $fileIOInstance An instance to the file I/O sub-system
+ * @return $fileIoInstance An instance to the file I/O sub-system
*/
protected final function getFileIoInstance () {
- return $this->fileIOInstance;
+ return $this->fileIoInstance;
}
/**
* Setter for file I/O instance
*
- * @param $fileIOInstance An instance to the file I/O sub-system
+ * @param $fileIoInstance An instance to the file I/O sub-system
* @return void
*/
- public final function setFileIoInstance (FileIoHandler $fileIOInstance) {
- $this->fileIOInstance = $fileIOInstance;
+ public final function setFileIoInstance (FileIoHandler $fileIoInstance) {
+ $this->fileIoInstance = $fileIoInstance;
}
/**
/**
*
*
- * @author Roland Haeder <webmaster@mxchange.org>
+ * @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
* for looking in storages like the database.
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* A helper class for cryptographical things like hashing passwords and so on
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* @throws UnsupportedCriteriaException If the criteria is unsupported
* @throws SqlException If an "SQL error" occurs
*/
- public function querySelect ($resultType, $tableName, Criteria $criteriaInstance) {
+ public function querySelect ($resultType, $tableName, LocalSearchCriteria $criteriaInstance) {
// The result is null by any errors
$resultData = null;
- // Is this criteria supported?
- if (!$criteriaInstance instanceof LocalSearchCriteria) {
- // Not supported by this database layer
- throw new UnsupportedCriteriaException(array($this, $criteriaInstance), self::EXCEPTION_REQUIRED_INTERFACE_MISSING);
- }
-
// Create full path name
$pathName = $this->getSavePath() . $tableName . '/';
* @return void
* @throws SqlException If an SQL error occurs
*/
- public function insertDataSet (StoreableCriteria $dataSetInstance) {
+ public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
// Create full path name
$fqfn = sprintf("%s%s/%s.%s",
$this->getSavePath(),
$registrationInstance->addElementsToDataSet($dataSetInstance);
// "Insert" this request instance completely into the database
- $this->getDatabaseInstance()->insertDataSet($dataSetInstance);
+ $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
}
}
* 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 DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer {
+class DebugConsoleOutput extends BaseFrameworkSystem implements Debugger, OutputStreamer, Registerable {
/**
* Protected constructor
*
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A general login helper class
+ *
+ * @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 BaseLoginHelper extends BaseHelper {
+ /**
+ * Protected constructor
+ *
+ * @param $className Real name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
* A general registration class
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* A registry for several data types
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* A database result class
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
* 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 DatabaseResult extends BaseFrameworkSystem {
+class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, SeekableIterator {
/**
* Current position in array
*/
// Is the result valid?
if ($this->resultArray['status'] === "ok") {
// The status is fine so let's have a look for the next entry
- if (isset($this->resultArray['rows'][($this->currentPos + 1)])) {
+ if ($this->valid()) {
// Next entry found, so count one up and cache it
$this->currentPos++;
$this->currentRow = $this->resultArray['rows'][$this->currentPos];
// Return the result
return $nextValid;
}
+
+ /**
+ * Seeks for to a specified position
+ *
+ * @param $index Index to seek for
+ * @return void
+ */
+ public function seek ($index) {
+ // Rewind to beginning
+ $this->rewind();
+
+ // Search for the entry
+ while ($this->currentPos < $index && ($this->valid())) {
+ // Continue on
+ $this->next();
+ } // END - while
+ }
+
+ /**
+ * Gives back the current position or null if not found
+ *
+ * @return $current Current element to give back
+ */
+ public function current () {
+ // Default is not found
+ $current = null;
+
+ // Does the current enty exist?
+ if (isset($this->resultArray['rows'][$this->currentPos])) {
+ // Then get it
+ $current = $this->resultArray['rows'][$this->currentPos];
+ } // END - if
+
+ // Return the result
+ return $current;
+ }
+
+ /**
+ * Checks if next() and rewind will give a valid result
+ *
+ * @return $isValid Wether the next/rewind entry is valid
+ */
+ public function valid () {
+ // By default nothing is valid
+ $isValid = false;
+
+ // Check if
+ if ((isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) {
+ // All fine!
+ $isValid = true;
+ } // END - if
+
+ // Return the result
+ return $isValid;
+ }
+
+ /**
+ * Gets the current key of iteration
+ *
+ * @return $currentPos Key from iterator
+ */
+ public function key () {
+ return $this->currentPos;
+ }
+
+ /**
+ * Rewind to the beginning
+ *
+ * @return void
+ */
+ public function rewind () {
+ $this->currentPos = 0;
+ }
+
+ /**
+ * Searches for an entry in the data result and returns it
+ *
+ * @param $criteriaInstance The criteria to look inside the data set
+ * @return $result Found result entry
+ */
+ public function searchEntry (LocalSearchCriteria $criteriaInstance) {
+ die("OK");
+ }
}
// [EOF]
* A standard random number generator
*
* @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.3.0
+ * @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.mxchange.org
+ * @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
// Exceptions
const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01;
+ const EXCEPTION_USER_PASS_MISMATCH = 0xd02;
/**
* Protected constructor
* @return $exists Wether the username exists
*/
public function ifUsernameExists () {
- // By default the username does exist
- $exists = true;
+ // By default the username does not exist
+ $exists = false;
// Get a UserDatabaseWrapper instance
$wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
$result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
// Search for it
- if (!$result->next()) {
- // Entry not found
- $exists = false;
+ if ($result->next()) {
+ // Entry found
+ $exists = true;
} // END - if
// Return the status
* @return $exists Wether the email exists
*/
public function ifEmailAddressExists () {
- // By default the username does exist
- $exists = true;
+ // By default the email does not exist
+ $exists = false;
// Get a UserDatabaseWrapper instance
$wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
$result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
// Search for it
- if (!$result->next()) {
- // Entry not found
- $exists = false;
+ if ($result->next()) {
+ // Entry found
+ $exists = true;
} // END - if
// Return the status
return $exists;
}
+
+ /**
+ * Checks if the supplied password hash in request matches with the stored
+ * in database.
+ *
+ * @param $requestInstance A requestable class instance
+ * @return $matches Wether the supplied password hash matches
+ */
+ public function ifPasswordHashMatches (Requestable $requestInstance) {
+ // By default nothing matches... ;)
+ $matches = false;
+
+ // Get a UserDatabaseWrapper instance
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper');
+
+ // Create a search criteria
+ $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria');
+
+ // Add the username as a criteria and set limit to one entry
+ $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName());
+ $criteriaInstance->setLimit(1);
+
+ // Get a search result
+ $result = $wrapperInstance->doSelectByCriteria($criteriaInstance);
+
+ // Search for it
+ if ($result->next()) {
+ // Get the current entry (can only be one!)
+ $entry = $result->current();
+
+ // So does the hashes match?
+ $matches = ($requestInstance->getRequestElement('pass_hash') === $entry['pass_hash']);
+ } // END - if
+
+ // Return the status
+ return $matches;
+ }
+
+ /**
+ * Adds data for later complete update
+ *
+ * @param $column Column we want to update
+ * @param $value New value to store in database
+ * @return void
+ */
+ public function addUpdateData ($column, $value) {
+ $this->partialStub("Column={$column}, value={$value}");
+ }
}
// [EOF]
* @param $dataSetInstance A storeable data set
* @return void
*/
- public function insertDataSet (StoreableCriteria $dataSetInstance) {
+ public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
// Connect to the database
$this->dbLayer->connectToDatabase();
// Ask the database layer
- $this->dbLayer->insertDataSet($dataSetInstance);
+ $this->dbLayer->queryInsertDataSet($dataSetInstance);
}
}