Using my own database and look

smaij

Joined: 2004-02-07
Posts: 3
Posted: Sat, 2004-02-07 10:55

I tried to follow the instructions descripted on http://www.txraves.org/code/dox/embedding_gallery.php

My Gallery @ the moment = http://images.kvkeistad.nl)

I got stuck on the UserDB.php file i think.

I can login in my own system (The header and footer do change) but I dont see any user rights.

Posted below are my files @ the moment

The changed bit of init.php

} elseif (!strcmp($GALLERY_EMBEDDED_INSIDE, "dtw")) {

	include($GALLERY_BASEDIR . "classes/dtw/UserDB.php");
	include($GALLERY_BASEDIR . "classes/dtw/common.inc.php");
	include($GALLERY_BASEDIR . "classes/dtw/User.php");
	include($GALLERY_BASEDIR . "classes/dtw/auth.inc.php");
	connecttodatabase();
	$gallery->userDB = new Dtw_UserDB;
	//$gallery->userDB = new Gallery_UserDB;
	
	global $ingelogd;
	$ingelogd = CheckLogin();
	if ($ingelogd){
		$gebruiker = $GLOBALS['HTTP_SESSION_VARS']['UserID'];
		$gallery->user = $gallery->userDB->getUserByUid($gebruiker);
	}

User.php

<?php
class Dtw_User extends Abstract_User {
	/*
	var $username;
	var $fullname;
	var $password;
	var $email;
	var $isAdmin;
	var $canCreateAlbums;
	var $uid;
	*/

	function Dtw_User($uid = '', $username = '', $email = '', $fullname = '', $isAdmin = '', $canCreateAlbums = ''){
			
			Abstract_User::Abstract_User();
			$this->uid = $uid;
			$this->username = $username;
			$this->email = $email;
			$this->fullname = $fullname;
			$this->isAdmin = $isAdmin;
			$this->canCreateAlbums = $canCreateAlbums;

	}


	function load($uid) {

		$query = mysql_query("SELECT UserID, UserName, Naam, Emailadres FROM users WHERE UserID = '$uid'") or die(mysql_error());
		if ($gebruiker = mysql_fetch_array($query)){
			
			$this->uid = $gebruiker['UserID'];
			$this->username = $gebruiker['UserName'];
			$this->email = $gebruiker['Emailadres'];
			$this->fullname = $gebruiker['Naam'];
			$this->isAdmin = true;
			$this->canCreateAlbums = true;

		}

	}

	function loadByUserName($username){
		$query = mysql_query("SELECT UserID, UserName, Naam, Emailadres FROM users WHERE UserName = '$username'") or die(mysql_error());
		if ($gebruiker = mysql_fetch_array($query)){
			
			$this->uid = $gebruiker['UserID'];
			$this->username = $gebruiker['UserName'];
			$this->email = $gebruiker['Emailadres'];
			$this->fullname = $gebruiker['Naam'];
			$this->isAdmin = true;
			$this->canCreateAlbums = true;

		}
	}
}

?>

UserDB.php

<?php
class Dtw_UserDB extends Abstract_UserDB {
/*
	var $userMap;
	var $nobody;
	var $everybody;
	var $loggedIn;
	var $version;
*/
	function Dtw_UserDB() {
		global $gallery;

		$userDir = $gallery->app->userDir;
		//echo $userDir;
		$this->version = $gallery->user_version;

		$this->userMap = array();

		$this->rebuildUserMap();

		//print_r($this->userMap);

		if (!$this->nobody) {
			$this->nobody = new NobodyUser();
		}

		if (!$this->everybody) {
			$this->everybody = new EverybodyUser();
		}

		if (!$this->loggedIn) {
			$this->loggedIn = new LoggedInUser();
		}


	}


	function getUserByUsername($username, $level=0) {
		global $gallery;

		if (!strcmp($username, $this->nobody->getUsername())) {
			return $this->nobody;
		} else if (!strcmp($username, $this->everybody->getUsername())) {
			return $this->everybody;
		} else if (!strcmp($username, $this->loggedIn->getUsername())) {
			return $this->loggedIn;
		}

		$user = new Dtw_User();
		return $user->loadByUserName($username);
	}

	function getUserByUid($uid, $tryOldFormat=false) {
		global $gallery;

		if (!$uid || !strcmp($uid, $this->nobody->getUid())) {
			return $this->nobody;
		} else if (!strcmp($uid, $this->everybody->getUid())) {
			return $this->everybody;
		} else if (!strcmp($uid, $this->loggedIn->getUid())) {
			return $this->loggedIn;
		}

		$user = new Dtw_User();
		return $user->load($uid);
	}

	function getUsername($uid) {
		return $this->userMap[$uid];
	}

	function getUid($username) {
		return $this->userMap[$username];
	}

	function rebuildUserMap() {
		global $gallery;
		$userDir = $gallery->app->userDir;

		$this->userMap = array();

		/*
		foreach ($this->getUidList() as $uid) {
			$tmpUser = $this->getUserByUid($uid);
			$username = $tmpUser->getUsername();
			$this->userMap[$username] = $uid;
			$this->userMap[$uid] = $username;
		}
		*/

		$query = mysql_query("SELECT UserID, UserName FROM users") or die(mysql_error());

		while ($arrayuid = mysql_fetch_array($query)){
			$username = $arrayuid['UserName'];
			$uid = $arrayuid['UserID'];
			$this->userMap[$username] = $uid;
			$this->userMap[$uid] = $username;
		}

		return safe_serialize($this, "$userDir/userdb.dat");

	}


	function getUidList() {
		global $gallery;
		
		$uidList = array();

		$query = mysql_query("SELECT UserID FROM users") or die(mysql_error());

		while ($arrayuid = mysql_fetch_array($query)){
			array_push($uidList, $arrayuid['UserID']);
		}

		array_push($uidList, $this->nobody->getUid());
		array_push($uidList, $this->everybody->getUid());
		array_push($uidList, $this->loggedIn->getUid());

		sort($uidList);
		return $uidList;
	}

}

?>

I hope somebody is able to understand my problem and can help me.

 
smaij

Joined: 2004-02-07
Posts: 3
Posted: Sun, 2004-02-08 11:01

This night I was looking @ this again and somehow I saw the wrong code:

return $user->loadByUserName($username); 

Wondering why i made this fault... I dont know...

Well.. Now that is done, I'm wondering how i can get Gallery Remote working.
I tried this:

Username: smaij
Password: ************

Gallery Type: PhpNuke

PhpNuke login module: http:// images.kvkeistad.nl/login2.php?login=1&Naam=$USERNAME$&Password=$PASSWORD$

Gallery Module name: http:// images.kvkeistad.nl/$GALLERYFILE$

Now i;m wondering if somebody could tell me what the loginscript should contain so the gallery knows i;m logged in or not.

 
smaij

Joined: 2004-02-07
Posts: 3
Posted: Sun, 2004-02-08 13:06

Ok.. I'm trying to get gallery remote working. But the things I dont know

Is de password md5 before submitting???
Wich file do I need to recode? (gallery_remote.php OR gallery_remote2.php)

I'm working with the newest Gallery Remote Software!

I tried gallery_remote and gallery_remote2 both.

1

if (!strcmp($cmd, "login")) {
/*
	if ($uname && $password) {
		
		$tmpUser = $gallery->userDB->getUserByUsername($uname);
		if ($tmpUser && $tmpUser->isCorrectPassword($password)) {
			$gallery->session->username = $uname;
			$returnval = "SUCCESS";
		} else {
			$returnval = "Login Incorrect";
		}
	} else {
		$returnval = "Missing Parameters";
	}
*/

	if ($uname && $password) {
		$Message = LoginUser($uname, $password, 0, true);
		If ($Message == 1){
			$gallery->session->username = $uname;
			$returnval = "SUCCESS";
		} else {
			$returnval = "Login Incorrect";
		}
	} else {
		$returnval = "Missing Parameters";
	}
	echo "$returnval";
}

2

if (!strcmp($cmd, "login")) {
	//---------------------------------------------------------
	//-- login --

	if ($uname && $password) {
		//echo $gallery->user->getUsername()."\n";
		//echo $gallery->user->isLoggedIn()."\n";

		if ($gallery->user->isLoggedIn()) {
			// we're embedded and the user is authenticated

			$response->setProperty( "server_version", $GR_VER['MAJ'].".".$GR_VER['MIN'] );
			$response->setProperty( "status", $GR_STAT['SUCCESS'] );
			$response->setProperty( "status_text", "Login successful." );

			// return the response
			echo $response->listprops();
			exit;
		}

		// try to log in using URL parameters (probably not embedded)
		/*
		$tmpUser = $gallery->userDB->getUserByUsername($uname);

		if ($tmpUser) {
			$response->setProperty( "debug_user", $tmpUser->getUsername());
			$response->setProperty( "debug_user_type", get_class($tmpUser));
		}

		if ($tmpUser && $tmpUser->isCorrectPassword($password)) {
			// log user in
			$gallery->session->username = $uname;
			
			$response->setProperty( "server_version", $GR_VER['MAJ'].".".$GR_VER['MIN'] );
			$response->setProperty( "status", $GR_STAT['SUCCESS'] );
			$response->setProperty( "status_text", "Login successful." );
		} else {
			$response->setProperty( "status", $GR_STAT['PASSWORD_WRONG'] );
			$response->setProperty( "status_text", "Password incorrect." );
		}
		*/

		$Message = LoginUser($uname, $password, 0, true);
		If ($Message == 1){
			$gallery->session->username = $uname;
			$response->setProperty( "server_version", $GR_VER['MAJ'].".".$GR_VER['MIN'] );
			$response->setProperty( "status", $GR_STAT['SUCCESS'] );
			$response->setProperty( "status_text", "Login successful." );
		} else {
			$response->setProperty( "status", $GR_STAT['PASSWORD_WRONG'] );
			$response->setProperty( "status_text", "Password incorrect." );
		}
	} else {
		$response->setProperty( "status", $GR_STAT['LOGIN_MISSING'] );
		$response->setProperty( "status_text", "Login parameters not found." );
	}

}
 
jasco

Joined: 2005-01-03
Posts: 3
Posted: Tue, 2005-01-04 02:02

I am having the exact same problem that smaij had in his first post but have no clue what he did to fix what ever the problem was in the second post. If someone could help me out here i would greatly appreciate it.

Thanks.