Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
Kalens - Blob - ViewGit - Blue Static
<?php
/*=====================================================================*\
|| ###################################################################
|| # Kalens [#]version[#]
|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
|| #
|| # 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; version [#]gpl[#] of the License.
|| #
|| # 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, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

$GLOBALS['isso:callback']->load('api', null);

/**
* API: User
*
* @author		Blue Static
* @copyright	Copyright ©2002 - [#]year[#], Blue Static
* @version		$Revision$
* @package		Kalens
*
*/
class UserAPI extends API
{
	/**
	* Table fields
	* @var	array
	*/
	var $fields = array(
		'userid'		=> array(TYPE_UINT,	REQ_AUTO,	'verify_nozero'),
		'username'		=> array(TYPE_STR,	REQ_YES,	':self'),
		'email'			=> array(TYPE_STR,	REQ_YES,	':self'),
		'salt'			=> array(TYPE_STR,	REQ_SET),
		'password'		=> array(TYPE_STR,	REQ_YES),
		'authkey'		=> array(TYPE_STR,	REQ_SET),
		'calendarids'	=> array(TYPE_STR,	REQ_NO)
	);

	/**
	* Database table
	* @var	string
	*/
	var $table = 'user';

	/**
	* Table prefix
	* @var	string
	*/
	var $prefix = TABLE_PREFIX;

	// ###################################################################
	/**
	* Set field: salt
	*
	* @access	private
	*/
	function set_salt()
	{
		$this->set('salt', $this->registry->funct->rand(array(1, 15)));
	}

	// ###################################################################
	/**
	* Set field: authkey
	*
	* @access	private
	*/
	function set_authkey()
	{
		$this->set('authkey', $this->registry->funct->rand());
	}

	// ###################################################################
	/**
	* Verify: email
	*
	* @access	private
	*/
	function verify_email()
	{
		if (!is_bool($ne = $this->verify_noempty('email')))
		{
			return $ne;
		}

		if (!$this->registry->funct->is_valid_email($this->values['email']))
		{
			return _('The specified email is invalid.');
		}
		if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->registry->escape($this->values['email']) . "' AND userid <> " . $this->registry->clean($this->values['userid'], TYPE_UINT)))
		{
			return _('The specified email is already in use.');
		}
		return true;
	}

	// ###################################################################
	/**
	* Verify: username
	*
	* @access	private
	*/
	function verify_username()
	{
		if (!is_bool($ne = $this->verify_noempty('username')))
		{
			return $ne;
		}

		if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE username = '" . $this->registry->escape($this->values['username']) . "' AND userid <> " . $this->registry->clean($this->values['userid'], TYPE_UINT)))
		{
			return _('That username is already in use by another user.');
		}
		return true;
	}

	// ###################################################################
	/**
	* Pre-insert
	*
	* @access	private
	*/
	function pre_insert()
	{
		$this->set('password', md5(md5($this->values['password']) . md5($this->values['salt'])));
	}

	// ###################################################################
	/**
	* Pre-update
	*
	* @access	private
	*/
	function pre_update()
	{
		$this->set_condition();
		$this->fetch();

		if ($this->values['password'] == '')
		{
			$this->set('password', $this->objdata['password']);
		}
		else
		{
			$this->set('password', md5(md5($this->values['password']) . md5($this->objdata['salt'])));
		}
	}
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>