Commit bec35da3 authored by Brett Wilkins's avatar Brett Wilkins

MaharaAuthPlugin: post- test-develop-test commit

Plugin is now working
parent 5a5877ad
<?php
/**
*/
require('GlobalFunctions.php');
# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
# http://www.mediawiki.org/
#
......@@ -40,28 +41,33 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool
*/
$dbname;
$host;
$dbname;
$prefix;
$dbuser;
$dbpass;
var $dbname;
var $host;
var $prefix;
var $dbtype;
var $dbuser;
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->host = $host;
$this->prefix = $prefix;
$this->dbtype = $dbtype;
$this->dbuser = $user;
$this->dbpass = $password;
wfDebugLog('mahara','authplugin constructed');
}
public function userExists( $username ) {
$db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname);
$sql = "SELECT username FROM ".$this->prefix."usr where username = '".$username."';";
$username = strtolower($username);
$db = $this->getDatabase();
$sql = "SELECT username FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql);
$val = $db->fetchRow($res);
$val = $db->fetchObject($res);
wfDebugLog('mahara',print_r($val,true));
$db->close();
if (!empty($val) && $val > 0) {
if (!empty($val)) {
return true;
}
return false;
......@@ -78,12 +84,14 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool
*/
public function authenticate( $username, $password ) {
$db = new Database($this->dbhost,$this->dbuser,$this->dbpass,$this->dbname);
$sql = "SELECT username, password, salt FROM ".$this->prefix."usr where username = '".$username"';"
$username = strtolower($username);
$db = $this->getDatabase();
$sql = "SELECT username, password, salt FROM ".$this->prefix."usr where username = '".$username."'";
wfDebugLog('mahara',$sql);
$res = $db->query($sql);
$val = $db->fetchRow($res);
$val = $db->fetchObject($res);
$db->close();
if (!empty($val) && $val > 0) {
if (!empty($val)) {
$passcheck = sha1($val->salt . $password);
if ($passcheck == $val->password) {
return true;
......@@ -133,7 +141,15 @@ class MaharaAuthPlugin extends AuthPlugin {
* @param User $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;
}
......@@ -224,7 +240,7 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool
*/
public function strict() {
return true;
return false;
}
/**
......@@ -235,7 +251,7 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool
*/
public function strictUserAuth( $username ) {
return true;
return false;
}
/**
......@@ -250,7 +266,16 @@ class MaharaAuthPlugin extends AuthPlugin {
* @param $autocreate bool True if user is being autocreated on login
*/
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 {
public function getUserInstance( User &$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