Fix comment
[lhc/web/wiklou.git] / includes / extauth / vB.php
1 <?php
2
3 # Copyright (C) 2009 Aryeh Gregor
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * This class supports the proprietary vBulletin forum system
22 * <http://www.vbulletin.com>, versions 3.5 and up. It calls no functions or
23 * code, only reads from the database. Example lines to put in
24 * LocalSettings.php:
25 *
26 * $wgExternalAuthType = 'vB';
27 * $wgExternalAuthConf = array(
28 * 'server' => 'localhost',
29 * 'username' => 'forum',
30 * 'password' => 'udE,jSqDJ<""p=fI.K9',
31 * 'dbname' => 'forum',
32 * 'tableprefix' => ''
33 * );
34 */
35 class ExternalUser_vB extends ExternalUser {
36 private $mDb, $mRow;
37
38 protected function initFromName( $name ) {
39 return $this->initFromCond( array( 'username' => $name ) );
40 }
41
42 protected function initFromId( $id ) {
43 return $this->initFromCond( array( 'userid' => $id ) );
44 }
45
46 # initFromCookie() not yet implemented
47
48 private function initFromCond( $cond ) {
49 global $wgExternalAuthConf;
50
51 $this->mDb = new Database(
52 $wgExternalAuthConf['server'],
53 $wgExternalAuthConf['username'],
54 $wgExternalAuthConf['password'],
55 $wgExternalAuthConf['dbname'],
56 false, 0,
57 $wgExternalAuthConf['tableprefix']
58 );
59
60 $row = $this->mDb->selectRow(
61 'user',
62 array( 'userid', 'username', 'password', 'salt', 'email', 'usergroupid',
63 'membergroupids' ),
64 $cond,
65 __METHOD__
66 );
67 if ( !$row ) {
68 return false;
69 }
70 $this->mRow = $row;
71
72 return true;
73 }
74
75 public function getId() { return $this->mRow->userid; }
76 public function getName() { return $this->mRow->username; }
77
78 public function authenticate( $password ) {
79 return $this->mRow->password == md5( md5( $password )
80 . $this->mRow->salt );
81 }
82
83 public function getPref( $pref ) {
84 if ( $pref == 'emailaddress' && $this->mRow->email ) {
85 # TODO: only return if validated?
86 return $this->mRow->email;
87 }
88 return null;
89 }
90
91 public function getGroups() {
92 $groups = array( $this->mRow->usergroupid );
93 $groups = array_merge( $groups, explode( ',', $this->mRow->membergroupids ) );
94 $groups = array_unique( $groups );
95 return $groups;
96 }
97 }