Commit bec35da3 authored by Brett Wilkins's avatar Brett Wilkins

MaharaAuthPlugin: post- test-develop-test commit

Plugin is now working
parent 5a5877ad
<?php <?php
/** /**
*/ */
require('GlobalFunctions.php');
# Copyright (C) 2004 Brion Vibber <brion@pobox.com> # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/ # http://www.mediawiki.org/
# #
...@@ -40,28 +41,33 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -40,28 +41,33 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool * @return bool
*/ */
$dbname; var $dbname;
$host; var $host;
$dbname; var $prefix;
$prefix; var $dbtype;
$dbuser; var $dbuser;
$dbpass; var $dbpass;
public __construct($dbname, $host='localhost', $prefix='', $user='', $password='') { public function __construct($dbname, $host='localhost',$dbtype='postgres', $user='', $password='', $prefix='') {
$this->dbname = $dbname; $this->dbname = $dbname;
$this->host = $host; $this->host = $host;
$this->prefix = $prefix; $this->prefix = $prefix;
$this->dbtype = $dbtype;
$this->dbuser = $user; $this->dbuser = $user;
$this->dbpass = $password; $this->dbpass = $password;
wfDebugLog('mahara','authplugin constructed');
} }
public function userExists( $username ) { public function userExists( $username ) {
$db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname); $username = strtolower($username);
$sql = "SELECT username FROM ".$this->prefix."usr where username = '".$username."';"; $db = $this->getDatabase();
$sql = "SELECT username FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql); $res = $db->query($sql);
$val = $db->fetchRow($res); $val = $db->fetchObject($res);
wfDebugLog('mahara',print_r($val,true));
$db->close(); $db->close();
if (!empty($val) && $val > 0) { if (!empty($val)) {
return true; return true;
} }
return false; return false;
...@@ -78,12 +84,14 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -78,12 +84,14 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool * @return bool
*/ */
public function authenticate( $username, $password ) { public function authenticate( $username, $password ) {
$db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname); $username = strtolower($username);
$sql = "SELECT username, password, salt FROM ".$this->prefix."usr where username = '".$username"';" $db = $this->getDatabase();
$sql = "SELECT username, password, salt FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql); $res = $db->query($sql);
$val = $db->fetchRow($res); $val = $db->fetchObject($res);
$db->close(); $db->close();
if (!empty($val) && $val > 0) { if (!empty($val)) {
$passcheck = sha1($val->salt . $password); $passcheck = sha1($val->salt . $password);
if ($passcheck == $val->password) { if ($passcheck == $val->password) {
return true; return true;
...@@ -133,7 +141,15 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -133,7 +141,15 @@ class MaharaAuthPlugin extends AuthPlugin {
* @param User $user * @param User $user
*/ */
public function updateUser( &$user ) { public function updateUser( &$user ) {
# Override this and do something $db = $this->getDatabase();
$sql = "SELECT * FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql);
$val = $db->fetchRow($res);
$db->close();
$user->setOption('nickname',$val->username);
$user->setEmail($this->email);
$user->setRealName($this->firstname.' '.$this->lastname);
return true; return true;
} }
...@@ -224,7 +240,7 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -224,7 +240,7 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool * @return bool
*/ */
public function strict() { public function strict() {
return true; return false;
} }
/** /**
...@@ -235,7 +251,7 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -235,7 +251,7 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool * @return bool
*/ */
public function strictUserAuth( $username ) { public function strictUserAuth( $username ) {
return true; return false;
} }
/** /**
...@@ -250,7 +266,16 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -250,7 +266,16 @@ class MaharaAuthPlugin extends AuthPlugin {
* @param $autocreate bool True if user is being autocreated on login * @param $autocreate bool True if user is being autocreated on login
*/ */
public function initUser( &$user, $autocreate=false ) { public function initUser( &$user, $autocreate=false ) {
# Override this to do something. $db = $this->getDatabase();
$sql = "SELECT * FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql);
$val = $db->fetchRow($res);
$db->close();
wfDebugLog('mahara',print_r($val,true),false);
$user->setOption('nickname',$val->username);
$user->setEmail($this->email);
$user->setRealName($this->firstname.' '.$this->lastname);
} }
/** /**
...@@ -270,6 +295,28 @@ class MaharaAuthPlugin extends AuthPlugin { ...@@ -270,6 +295,28 @@ class MaharaAuthPlugin extends AuthPlugin {
public function getUserInstance( User &$user ) { public function getUserInstance( User &$user ) {
return new AuthPluginUser( $user ); return new AuthPluginUser( $user );
} }
private function getDatabase() {
if (empty($this->dbtype)) {
return false;
}
switch ($this->dbtype) {
case 'mysql':
return new DatabaseMysql($this->host,$this->dbuser,$this->dbpass,$this->dbname);
break;
case 'mssql':
return new DatabaseMssql($this->host,$this->dbuser,$this->dbpass,$this->dbname);
break;
case 'oracle':
return new DatabaseOracle($this->host,$this->dbuser,$this->dbpass,$this->dbname);
break;
case 'postgres':
default:
return new DatabasePostgres($this->host,$this->dbuser,$this->dbpass,$this->dbname);
break;
}
return false;
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment