Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
scripts
mediawiki-auth-mahara
Commits
bec35da3
Commit
bec35da3
authored
Sep 27, 2010
by
Brett Wilkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MaharaAuthPlugin: post- test-develop-test commit
Plugin is now working
parent
5a5877ad
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
19 deletions
+66
-19
MaharaAuthPlugin.php
MaharaAuthPlugin.php
+66
-19
No files found.
MaharaAuthPlugin.php
View file @
bec35da3
<?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
->
fetch
Row
(
$res
);
$val
=
$db
->
fetch
Object
(
$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
tru
e
;
return
fals
e
;
}
/**
...
...
@@ -235,7 +251,7 @@ class MaharaAuthPlugin extends AuthPlugin {
* @return bool
*/
public
function
strictUserAuth
(
$username
)
{
return
tru
e
;
return
fals
e
;
}
/**
...
...
@@ -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
;
}
}
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment