]>
src.bluestatic.org Git - bugdar.git/blob - includes/auth/auth_drupal.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 require_once('./includes/auth/auth.php');
25 * Authentication: Drupal
28 * @copyright Copyright (c)2002 - 2007, Blue Static
33 class AuthenticationDrupal
extends Authentication
36 * Map for Bugdar fields to Drupal fields
38 var $fieldMap = array(
40 'displayname' => 'name',
45 * The cookie name to use for Drupal. Leaving this NULL will get it from session_name()
47 var $cookieName = null;
49 // ###################################################################
50 function _setupDatabase()
52 parent
::_setupDatabase();
54 // check and see if we need to call session_name()
55 include 'includes/auth/config.php';
56 $this->cookieName
= $config['auth']['Drupal']['cookieName'];
57 $this->cookieName
= ($this->cookieName
== null ? session_name() : $this->cookieName
);
60 // ###################################################################
61 function _fetchCookieUniqueId()
63 return BSApp
::$input->in
[$this->cookieName
];
66 // ###################################################################
67 function _fetchCookiePassword()
72 // ###################################################################
73 function _fetchUserUsingCookies()
75 $session = $this->authDb
->queryFirst("SELECT * FROM sessions WHERE sid = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
76 if (!$session OR $session['uid'] == 0)
80 return $this->authDb
->queryFirst("SELECT * FROM users WHERE uid = " . $session['uid']);
83 // ###################################################################
84 function _verifyCookieData()
86 return ($this->_fetchUserUsingCookies() != false);
89 // ###################################################################
90 function _fetchUserWithIdentifier($string)
92 return $this->authDb
->queryFirst("SELECT * FROM users WHERE name = '" . $this->authDb
->escapeString($string) . "'");
95 // ###################################################################
96 function _verifyLoginUser($password)
98 return (md5($password) == $this->authUser
['pass']);
101 // ###################################################################
102 function clearCookies()
104 BSFunctions
::cookie($this->cookieName
);
105 $this->authDb
->query("DELETE FROM sessions WHERE sid = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
108 // ###################################################################
109 function _setCookies($permanent = false)
111 $sid = $this->_fetchCookieUniqueId();
112 $sid = ($sid ? $sid : md5(microtime() . rand()));
113 BSFunctions
::cookie($this->cookieName
, $sid, $permanent);
114 $this->authDb
->query("REPLACE INTO sessions (sid, uid, hostname, timestamp) VALUES ('$sid', '" . $this->authUser
['uid'] . "', '" . $this->authDb
->escapeString($_SERVER['REMOTE_ADDR']) . "', " . time() . ")");