]> src.bluestatic.org Git - bugdar.git/blob - includes/auth/auth_drupal.php
Bump framework version
[bugdar.git] / includes / auth / auth_drupal.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 require_once('./includes/auth/auth.php');
23
24 /**
25 * Authentication: Drupal
26 *
27 * @author Blue Static
28 * @copyright Copyright (c)2002 - 2007, Blue Static
29 * @version $Revision$
30 * @package Bugdar
31 *
32 */
33 class AuthenticationDrupal extends Authentication
34 {
35 /**
36 * Map for Bugdar fields to Drupal fields
37 */
38 var $fieldMap = array(
39 'authid' => 'uid',
40 'displayname' => 'name',
41 'email' => 'mail',
42 );
43
44 /**
45 * The cookie name to use for Drupal. Leaving this NULL will get it from session_name()
46 */
47 var $cookieName = null;
48
49 // ###################################################################
50 function _setupDatabase()
51 {
52 parent::_setupDatabase();
53
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);
58 }
59
60 // ###################################################################
61 function _fetchCookieUniqueId()
62 {
63 return BSApp::$input->in[$this->cookieName];
64 }
65
66 // ###################################################################
67 function _fetchCookiePassword()
68 {
69 return true;
70 }
71
72 // ###################################################################
73 function _fetchUserUsingCookies()
74 {
75 $session = $this->authDb->queryFirst("SELECT * FROM sessions WHERE sid = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'");
76 if (!$session OR $session['uid'] == 0)
77 {
78 return false;
79 }
80 return $this->authDb->queryFirst("SELECT * FROM users WHERE uid = " . $session['uid']);
81 }
82
83 // ###################################################################
84 function _verifyCookieData()
85 {
86 return ($this->_fetchUserUsingCookies() != false);
87 }
88
89 // ###################################################################
90 function _fetchUserWithIdentifier($string)
91 {
92 return $this->authDb->queryFirst("SELECT * FROM users WHERE name = '" . $this->authDb->escapeString($string) . "'");
93 }
94
95 // ###################################################################
96 function _verifyLoginUser($password)
97 {
98 return (md5($password) == $this->authUser['pass']);
99 }
100
101 // ###################################################################
102 function clearCookies()
103 {
104 BSFunctions::cookie($this->cookieName);
105 $this->authDb->query("DELETE FROM sessions WHERE sid = '" . $this->authDb->escapeString($this->_fetchCookieUniqueId()) . "'");
106 }
107
108 // ###################################################################
109 function _setCookies($permanent = false)
110 {
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() . ")");
115 }
116 }
117
118 ?>