--- /dev/null
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar [#]version[#]
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # 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
+|| ###################################################################
+\*=====================================================================*/
+
+require_once('./includes/auth/auth.php');
+
+/**
+* Authentication: Drupal
+*
+* @author Blue Static
+* @copyright Copyright (c)2002 - [#]year[#], Blue Static
+* @version $Revision$
+* @package Bugdar
+*
+*/
+class AuthenticationDrupal extends Authentication
+{
+ /**
+ * Map for Bugdar fields to Drupal fields
+ */
+ var $fieldMap = array(
+ 'authid' => 'uid',
+ 'displayname' => 'name',
+ 'email' => 'mail',
+ );
+
+ /**
+ * The cookie name to use for Drupal. Leaving this NULL will get it from session_name()
+ */
+ var $cookieName = null;
+
+ // ###################################################################
+ function _setupDatabase()
+ {
+ // check and see if we need to call session_name()
+ $this->cookieName = ($this->cookieName == null ? session_name() : $this->cookieName);
+
+ // connect to the DB
+ $this->authDb = new DB_MySQL($this->registry);
+ $this->authDb->connect('DRUPAL_DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME', false);
+ }
+
+ // ###################################################################
+ function _fetchCookieUniqueId()
+ {
+ if ($sessionId == null)
+ {
+ $this->sessionId = $this->registry->in[ $this->cookieName ];
+ }
+ return $this->sessionId;
+ }
+
+ // ###################################################################
+ function _fetchCookiePassword()
+ {
+ return true;
+ }
+
+ // ###################################################################
+ function _fetchUserUsingCookies()
+ {
+ $session = $this->authDb->query_first("SELECT * FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'");
+ if (!$session OR $session['uid'] == 0)
+ {
+ return false;
+ }
+ return $this->authDb->query_first("SELECT * FROM users WHERE uid = " . $session['uid']);
+ }
+
+ // ###################################################################
+ function _verifyCookieData()
+ {
+ return ($this->_fetchUserUsingCookies() != false);
+ }
+
+ // ###################################################################
+ function _fetchUserWithIdentifier($string)
+ {
+ return $this->authDb->query_first("SELECT * FROM users WHERE name = '" . $this->authDb->escape_string($string) . "'");
+ }
+
+ // ###################################################################
+ function _verifyLoginUser($password)
+ {
+ return (md5($password) == $this->authUser['pass']);
+ }
+
+ // ###################################################################
+ function clearCookies()
+ {
+ $this->registry->funct->cookie($this->cookieName);
+ $this->authDb->query("DELETE FROM sessions WHERE sid = '" . $this->authDb->escape_string($this->_fetchCookieUniqueId()) . "'");
+ }
+
+ // ###################################################################
+ function _setCookies($permanent = false)
+ {
+ $sid = $this->_fetchCookieUniqueId();
+ $sid = ($sid ? $sid : md5(microtime() . rand()));
+ $this->registry->funct->cookie($this->cookieName, $sid, $permanent);
+ $this->authDb->query("REPLACE INTO sessions (sid, uid, hostname, timestamp) VALUES ('$sid', '" . $this->authUser['uid'] . "', '" . $this->authDb->escape_string($_SERVER['REMOTE_ADDR']) . "', " . time() . ")");
+ }
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file