Location: PHPKode > projects > Simple Way to Usenet > swun/libs/core/auth/accs/acc_array.class.php
<?php
/**
 * 
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	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 2
	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 at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */

class acc_array {
	
	private $USERS	= Array();
	private $GROUPS	= Array();
	private $MBRSHIP= Array();	
	private $realm, $aref;
	

	public function __construct($realm, $aref){
		$this->realm = $realm;
		$this->aref = $aref;
		unset($realm, $aref);
		$hash = configs::get('account', $this->aref, 'hash');
		if ( FALSE === $hash  ){ 
			errors::raise('Account "'.$aref.'" used in realm "'.$realm.'" is missing "hash" option, using md5 mode', CORE_LOG_WARNING, 'REALM');
			configs::set('account', $this->aref, 'MD5','hash');
		}
		$this->USERS 	= configs::get('account', $this->aref, Array('conf', 'users'));
		$this->GROUPS 	= configs::get('account', $this->aref, Array('conf', 'groups'));
		$this->MBRSHIP	= configs::get('account', $this->aref, Array('conf', 'mbrship'));
		errors::raise('Account Array "'.$this->aref.'" loaded '.count($this->USERS).' users, '.count($this->GROUPS).' groups', CORE_LOG_NOTICE, 'REALM');
	}
	
	public function authcheck($login, $pass){
		foreach($this->USERS as $k => $user ){
			if ( $login == $user['login'] AND $pass == $user['pass'] ){ return $k; }
		}
		return FALSE;
	}
	
	public function getpass($uid){ return $this->infobyuid('pass', $uid); }
	
	public function cookcheck($login, $key){
		return 'Sorry, but your account is stored on a backend that is not compatible with cookies autologin';
	}
	
	public function ismemberof($uid){
		foreach($this->MBRSHIP as $k => $gids ){
			if ( $k == $uid){return Array(0	=> $gids, 1 => Array()); }
		}
		 return Array(	0 	=> Array(), 
	 					1	=> Array() );
	}

	//dummy, not persistant write possible into conf array
	public function set_cookey($uid, $key){ 	return FALSE; }
	
	public function set_lastlogin($uid, $time){	return TRUE; }
	
	public function islocked($uid){ 			return FALSE; }
	
	public function lock($uid){ 				return TRUE; }
	
	public function unlock($uid){ 				return TRUE; }
	
	
	public function infobyuid($info, $uid){
		if ( isset($this->USERS[$uid]) ){
			if ( isset($this->USERS[$uid][$info]) ){ return $this->USERS[$uid][$info]; }
		}
		return FALSE;
	}
	
	public function infobylogin($info, $login){ 
		foreach($this->USERS as $k => &$user ){
			if ( $login == $user['login'] ){
				if ( $info == 'uid' ){ return $k; }
				if ( isset($user[$info]) ){ return $user[$info]; }
			}
		} 	
		return FALSE;
	}
	
	public function groupbygid($gid){ 			
		if ( isset($this->GROUPS[$gid]) ){ return $this->GROUPS[$gid]; }
		return FALSE;
	}
	
}
return TRUE;
Return current item: Simple Way to Usenet