<?php
/**
- * A class for mismatching passwords
+ * An exception for mismatching passwords
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
--- /dev/null
+<?php
+/**
+ * An exception for unexpected guest accounts
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 UnexpectedGuestAccountException 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 %s is a guest account.',
+ $msgArray[0]->__toString(),
+ $this->getLine(),
+ $msgArray[1]
+ );
+
+ // Make sure everything is assigned properly
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
<?php
/**
- * A class for non-existing user emails
+ * An exception for non-existing user emails
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
--- /dev/null
+<?php
+/**
+ * An exception for non-guest accounts (but guest was expected)
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 UserNoGuestException 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 %s is not a guest account: %s',
+ $msgArray[0]->__toString(),
+ $this->getLine(),
+ $msgArray[1],
+ $msgArray[0]->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS)
+ );
+
+ // Make sure everything is assigned properly
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
<?php
/**
- * A class for mismatching passwords
+ * An exception for mismatching passwords
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
<?php
/**
- * A class for non-existing usernames
+ * An exception for non-existing usernames
*
* @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
$userInstance = Registry::getRegistry()->getInstance('user');
// Is the user account confirmed?
- if (($userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) != $this->getConfigInstance()->getConfigEntry('user_status_confirmed')) && ($userInstance->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) != $this->getConfigInstance()->getConfigEntry('user_status_guest')) && ($requestInstance->getRequestElement('action') != $this->getConfigInstance()->getConfigEntry('action_status_problem'))) {
+ if ((!$userInstance->isConfirmed()) && (!$userInstance->isGuest()) && ($requestInstance->getRequestElement('action') != $this->getConfigInstance()->getConfigEntry('action_status_problem'))) {
// Request is invalid!
$requestInstance->requestIsValid(FALSE);
// Remember the update in database result
$this->getResultInstance()->add2UpdateQueue($updateInstance);
}
+
+ /**
+ * Checks whether the user status is 'confirmed'
+ *
+ * @return $isConfirmed Whether the user status is 'confirmed'
+ */
+ public function isConfirmed () {
+ // Determine it
+ $isConfirmed = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_confirmed'));
+
+ // Return it
+ return $isConfirmed;
+ }
+
+ /**
+ * Checks whether the user status is 'guest'
+ *
+ * @return $isGuest Whether the user status is 'guest'
+ */
+ public function isGuest () {
+ // Determine it
+ $isGuest = ($this->getField(UserDatabaseWrapper::DB_COLUMN_USER_STATUS) == $this->getConfigInstance()->getConfigEntry('user_status_guest'));
+
+ // Return it
+ return $isGuest;
+ }
}
// [EOF]
const EXCEPTION_USERNAME_NOT_FOUND = 0x170;
const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x171;
const EXCEPTION_USER_PASS_MISMATCH = 0x172;
+ const EXCEPTION_USER_NOT_GUEST = 0x173;
/**
* Protected constructor
* @param $userName Username we need a class instance for
* @return $userInstance An instance of this user class
* @throws UsernameMissingException If the username does not exist
+ * @throws UserNoGuestException If the user is no guest account
*/
public static final function createGuestByUsername ($userName) {
// Get a new instance
if ($userInstance->ifUsernameExists() === FALSE) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
- } // END - if
+ } elseif ($userInstance->isGuest() === FALSE) {
+ // Sanity check on 'guest' status failed
+ throw new UserNoGuestException(array($userInstance, $userName), self::EXCEPTION_USER_NOT_GUEST_STATUS);
+ }
// Return the instance
return $userInstance;
* @param $userName Username we need a class instance for
* @return $userInstance An instance of this user class
* @throws UsernameMissingException If the username does not exist
+ * @throws UnexpectedGuestAccountException If the user status is 'guest'
*/
public static final function createMemberByUsername ($userName) {
// Get a new instance
if ($userInstance->ifUsernameExists() === FALSE) {
// Throw an exception here
throw new UsernameMissingException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
- } // END - if
+ } elseif ($userInstance->isGuest()) === TRUE) {
+ // User should not be a guest here
+ throw new UnexpectedGuestAccountException(array($userInstance, $userName), self::EXCEPTION_USERNAME_NOT_FOUND);
+ }
// Return the instance
return $userInstance;
$updateInstance = ObjectFactory::createObjectByConfiguredName('update_criteria_class');
// And add our both entries
- $updateInstance->addCriteria("last_activity", date("Y-m-d H:i:s", time()));
- $updateInstance->addCriteria("last_action", $lastAction);
+ $updateInstance->addCriteria('last_activity', date('Y-m-d H:i:s', time()));
+ $updateInstance->addCriteria('last_action', $lastAction);
// Add the search criteria for searching for the right entry
$updateInstance->setSearchInstance($searchInstance);