From 9b390408ea3e036a28301e6f5b48b6a90f8fe008 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 30 Apr 2006 04:34:18 +0000 Subject: [PATCH] r781: Adding user API class --- includes/api_user.php | 183 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 includes/api_user.php diff --git a/includes/api_user.php b/includes/api_user.php new file mode 100644 index 0000000..a1d92b6 --- /dev/null +++ b/includes/api_user.php @@ -0,0 +1,183 @@ +load('api', null); + +/** +* API: User +* +* @author Iris Studios, Inc. +* @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc. +* @version $Revision$ +* @package Bugdar +* +*/ +class UserAPI extends API +{ + /** + * Database fields + * @var array + * @access private + */ + var $fields = array( + 'userid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'), + 'email' => array(TYPE_STR, REQ_YES, ':self'), + 'displayname' => array(TYPE_STR, REQ_YES, ':self'), + 'usergroupid' => array(TYPE_UINT, REQ_YES, ':self'), + 'password' => array(TYPE_STR, REQ_YES), + 'salt' => array(TYPE_STR, REQ_SET), + 'authkey' => array(TYPE_STR, REQ_SET), + 'showemail' => array(TYPE_BOOL, REQ_NO), + 'showcolours' => array(TYPE_BOOL, REQ_NO), + 'languageid' => array(TYPE_UINT, REQ_NO), + 'timezone' => array(TYPE_INT, REQ_NO) + ); + + /** + * Database table + * @var string + * @access private + */ + var $table = 'user'; + + /** + * Table prefix + * @var string + * @access private + */ + 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()); + } + + // ################################################################### + /** + * Pre-insert + * + * @access private + */ + function pre_insert() + { + $this->set('password', md5(md5($this->values['password']) . md5($this->values['salt']))); + } + + // ################################################################### + /** + * Verify: email + * + * @access private + */ + function verify_email() + { + $this->verify_noempty('displayname'); + + if ($this->registry->funct->is_valid_email($this->values['email'])) + { + return $this->registry->lang->string('The specified email is invalid.'); + } + if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE email = '" . $this->registry->db->escape_string($this->values['email']) . "'")) + { + return $this->registry->lang->string('The specified email is already in use.'); + } + return true; + } + + // ################################################################### + /** + * Verify: displayname + * + * @access private + */ + function verify_displayname() + { + $this->verify_noempty('displayname'); + + if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE displayname = '" . $this->registry->db->escape_string($this->values['displayname']) . "'")) + { + return $this->registry->lang->string('That display name is already in use by another user.'); + } + return true; + } + + // ################################################################### + /** + * Verify: usergroupid + * + * @access private + */ + function verify_usergroupid() + { + if (!isset($this->registry->datastore['usergroup'][ $this->values['usergroupid'] ])) + { + return false; + } + return true; + } + + // ################################################################### + /** + * Pre-update + * + * @access private + */ + function pre_update() + { + $this->set_condition(); + $this->fetch(); + + if ($this->values['password'] == '') + { + $this->set('password', $this->objdata['password']); + } + else + { + $this->registry->debug("updating password = true"); + $this->set('password', md5(md5($this->values['password']) . md5($this->objdata['salt']))); + } + } +} + +/*=====================================================================*\ +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5