Hi guys and girls.
This is what I'm wanting: I'm using a PHP Gedcom Viewer found at
http://phpgedview.sourceforge.net/ that is independent of Nuke or MySQL. It uses it's own user database via a file called authentication.php.
The creator of the software, John Finlay said that he
|
Quote:
|
|
designed the authentication system to be modular so that it could easily be modified to work with a phpNuke user database. You could implement the functions in authentication.php to recognize your phpNuke users. phpGedView only cares that the functions in that file exist, not how they are implemented.
|
.
This is something I'm very interested in seeing implemented into his project. Not only would I like to use the existing nuke user db, but I want it also to be a module, not the iframe module I have now.
The code is as follows:
|
Code:
|
===================================================*/
//-- file that holds the users array
require "authenticate.php";
//====================================================================
//-- The following functions must be implemented by anyone wishing to
//-- extend the authentication functionality of PhpGedView
//====================================================================
//----------------------------------- authenticateUser
//-- requires a username and password and
//-- returns true if the username and password
//-- pair allow access
function authenticateUser($username, $password) {
global $users;
if (array_key_exists($username, $users)) {
$user = $users[$username];
if (crypt($password, $user["password"])==$user["password"]) {
setcookie("pgv_user", $username, time()+3600);
return true;
}
}
return false;
}
//----------------------------------- userLogout
//-- logs a user out of the system
function userLogout() {
global $pgv_user;
setcookie("pgv_user", "loggedout", time()-3600);
$pgv_user = "loggedout";
}
//----------------------------------- getUserName
//-- retrieve the username from the state
//-- however you are storing it. The default
//-- implemenation uses a cookie
function getUserName() {
global $pgv_user;
if (isset($pgv_user)) {
if ($pgv_user=="loggedout") return "";
return $pgv_user;
}
return "";
}
//----------------------------------- userIsAdmin
//-- takes a username and checks if the
//-- user has administrative privileges
//-- to change the configuration files
function userIsAdmin($username) {
global $users;
if (array_key_exists($username, $users)) {
$user = $users[$username];
return $user["canadmin"];
}
return false;
}
//----------------------------------- userCanEdit
//-- takes a username and checks if the
//-- user has write privileges to change
//-- the gedcom data
function userCanEdit($username) {
global $users;
if (array_key_exists($username, $users)) {
$user = $users[$username];
return $user["canedit"];
}
return false;
}
//----------------------------------- adminUserExists
//-- return true if an admin user has been defined
function adminUserExists() {
global $users;
if (count($users)==0) return false;
return true;
}
//----------------------------------- storeUsers
//-- writes the users to the file
function storeUsers() {
global $users;
$authtext = "<?php\n\n\$users = array();\n\n";
foreach($users as $key=>$user) {
$authtext .= "\$user = array();\n";
foreach($user as $ukey=>$value) {
$value = preg_replace('/"/', '\\"', $value);
$authtext .= "\$user[\"$ukey\"] = '$value';\n";
}
$authtext .= "\$users[\"$key\"] = \$user;\n\n";
}
$authtext .= "?>\n";
$fp = fopen("authenticate.php", "w");
if ($fp===false) {
print "<font class=error>Could not open authentication.php file for writing. Check file permissions.</font>
";
return false;
}
fwrite($fp, $authtext);
fclose($fp);
return true;
}
//----------------------------------- addUser
//-- adds a new user.
//-- requires the newuser parameter to be an array
function addUser($newuser) {
global $users;
$users[$newuser["username"]]=$newuser;
return storeUsers();
}
//----------------------------------- deleteUser
//-- deletes the user with the given username.
function deleteUser($username) {
global $users;
unset($users[$username]);
return storeUsers();
}
//----------------------------------- getUser
//-- returns an array for the user with the given username.
function getUser($username) {
global $users;
return $users[$username];
}
//-----------------------------------
//-- if user wishes to logout this is where we will do it
if ((!empty($logout))&&($logout==1)) {
userLogout();
}
?> |
The phpgedview folder is currently placed in the root directory (normaly and the authentication file is in that folder. Does anyone recognize how this can be done? If so, I know I would appreciate the help, and John said he would add this to his next update on the software if we can get it working.
Thanks for any help.
Murph