[geeklog-cvs] Geeklog-2/system AccountManager.php,NONE,1.1 AccountManagerInterface.php,NONE,1.1 DefaultAccountManager.php,NONE,1.1

tony at iowaoutdoors.org tony at iowaoutdoors.org
Mon Dec 20 17:10:38 EST 2004


Update of /var/cvs/Geeklog-2/system
In directory www:/tmp/cvs-serv28006

Added Files:
	AccountManager.php AccountManagerInterface.php 
	DefaultAccountManager.php 
Log Message:
Some new files.  Not sure why all propel classes are listed every time...sorry


--- NEW FILE: AccountManagerInterface.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */
/**
 * Geeklog 2
 *
 * License Details To Be Determined
 *
 */
 
/**
 * This is the interface that all Account Managers must implement.
 *
 * Account Managers will allow Geeklog to better meet the more complex needs
 * of an enterprise.
 *
 * @copyright 2004 Tony Bibbs
 * @author Tony Bibbs <tony at geeklog.net>
 *
 */
interface Geeklog_AccountManagerInterface {
	public function createAccount();
	public function deleteAccount();
	public function authenticate();
	public function changePassword();
}

?>
--- NEW FILE: AccountManager.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */
/**
 * Geeklog 2
 *
 * License Details To Be Determined
 *
 */
 
/**
 * This class manages the various AccountManagers that my have been shipped or 
 * customized.
 *
 * @copyright 2004 Tony Bibbs
 * @author Tony Bibbs <tony at geeklog.net>
 *
 */
class Geeklog_AccountManager {
	public static function &singleton($managerName, $managerOptions)
	{
		global $glConf;
				
		$fileToInclude = $glConf['path_system']  . $managerName . '.php';
		if (include_once($fileToInclude)) {
			// Get around Geeklog 2 coding standards
			if ($managerName == 'DefaultAccountManager') {
				$managerName = 'Geeklog_DefaultAccountManager';
			}
            if (class_exists($managerName)) {
                return new $managerName($managerOptions);
            }
        }
	}

	public static function &factory($managerName, $managerOptions)
	{
		static $instances;
		
        if (!isset($instances)) {
            $instances = array();
        }

        $hash = serialize(array($managerName, $managerOptions));
        if (!isset($instances[$hash])) {
            $instances[$hash] = &self::factory($managerName, $managerOptions);
        }

        return $instances[$hash];
	}
}

?>
--- NEW FILE: DefaultAccountManager.php ---
<?php

/**
 * Account Manager Interface
 */
require_once 'AccountManagerInterface.php';

/**
 * DAO Factory
 */
require_once 'DataAccess/DAOFactory.php';

/**
 * This is the only Account Manager shipped with Geeklog 2, hence, it is the default.
 *
 * This account manager works directly against the Geeklog 2 database.  Other managers can be 
 * written to work against data stores other than the Geeklog 2 database (i.e. LDAP, Radius, etc).
 *
 * @copyright 2004 Tony Bibbs
 * @author Tony Bibbs <tony at geeklog.net>
 *
 */
class Geeklog_DefaultAccountManager implements Geeklog_AccountManagerInterface  {
	public function createAccount()
	{
	}
	
	public function deleteAccount()
	{
	}
	
	/**
	 * Authenticates a user against the user Geeklog 2 database
	 *
	 * @author Tony Bibbs <tony at geeklog.net>
	 * @access public
	 * @return string Name of MVCnPHP forward
	 *
	 */
	public function authenticate()
	{
		// Create user model object
		$user = new Gl2User();
		
		// Get Data Access Object
		$dao = Geeklog_DAOFactory::getDAO();
		
		// Get the user object
		$retval = $dao->find('getUserByUserName', array($_POST['username']));
		if (count($retval) == 0) {
			// Ok, couldn't find the user...bail
			$_REQUEST[MVC_ERRORS][] = 'Invalid Username';
			return 'backToLogin';
		}
		$user = $retval[0];
		
		// Ensure the password matches.
		if ($user->getPassword() <> $_POST['password']) {
			// Bad password, bail
			$_REQUEST[MVC_ERRORS][] = 'Invalid password';
			return 'backToLogin';
		}
		
		// Save user object to session
		$_SESSION['user'] = serialize($user);
		
		// Success, let the user in
		return 'goHome';
	}
	
	public function changePassword()
	{
	}
}

?>



More information about the geeklog-cvs mailing list