Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: User Authentication Class [Re: swebs] #317432
07/21/2008 7:07 PM
07/21/2008 7:07 PM
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Gizmo Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Gizmo  Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Originally Posted by swebs
The problem is that I have a bunch of dynamic pages that call eachother. I would have to create a bunch of wrapper pages.

Is there any way to create 1 file the I can include in my code to add the header and footer of the site?
I did this for a client over at www.jrdrags.com actually... Let me know if it's what you're looking for and I'll throw the mockup up here... (check out the side navbar, all links go through a central location)


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Sponsored Links
Re: User Authentication Class [Re: swebs] #317646
11/06/2008 2:00 AM
11/06/2008 2:00 AM
Joined: Jun 2001
Posts: 56
I
intensity Offline
Power User
intensity  Offline
Power User
I
Joined: Jun 2001
Posts: 56
I'm getting this weird error. Any ideas? Running php.v.5.2.6 and threads.v.7.3.1

Fatal error: Call to undefined function array_get() in xxx/forum/libs/mysql.inc.php on line 150

Re: User Authentication Class [Re: intensity] #317647
11/06/2008 8:02 AM
11/06/2008 8:02 AM
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Gizmo Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Gizmo  Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
i don't think its compatible with 7.3 or newer


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Re: User Authentication Class [Re: Gizmo] #317648
11/06/2008 11:58 AM
11/06/2008 11:58 AM
Joined: Jun 2001
Posts: 56
I
intensity Offline
Power User
intensity  Offline
Power User
I
Joined: Jun 2001
Posts: 56
I wasn't sure when Blaaskaak said he has it working if he meant unmodified or if he had to modify it. Nonetheless the error is a bit weird. Any help getting this working for me would be hugely appreciated.

Re: User Authentication Class [Re: intensity] #317657
11/08/2008 5:59 AM
11/08/2008 5:59 AM
Joined: Feb 2007
Posts: 330
The Netherlands
B
blaaskaak Offline
Yarp™
blaaskaak  Offline
Yarp™
B
Joined: Feb 2007
Posts: 330
The Netherlands
Will post my updated version tomorrow. Do mind that it does not support the new 7.3 permission matrix.


[Linked Image]
Sponsored Links
Re: User Authentication Class [Re: blaaskaak] #317658
11/09/2008 5:04 AM
11/09/2008 5:04 AM
Joined: Feb 2007
Posts: 330
The Netherlands
B
blaaskaak Offline
Yarp™
blaaskaak  Offline
Yarp™
B
Joined: Feb 2007
Posts: 330
The Netherlands
PHP Code


<?php
require('/home/themeparknl/html/themepark.nl/ubb/libs/smarty/Smarty.class.php');
$smarty = new Smarty();

$smarty->template_dir = 'templates/default';
$smarty->compile_dir = 'templates/compile';

require_once( "/home/themeparknl/html/themepark.nl/ubb/includes/config.inc.php" );
require_once( "/home/themeparknl/html/themepark.nl/ubb/libs/mysql.inc.php" );
require_once( "/home/themeparknl/html/themepark.nl/ubb/libs/html.inc.php");
require_once( "/home/themeparknl/html/themepark.nl/ubb/libs/ubbthreads.inc.php" );

$dbh = new sql;
$dbh->connect();

class admin {
	function error( $x ) {
		echo 'SQL error';
		die;
	}
}

//function getmicrotime(){
//	list( $usec, $sec ) = explode( " ", microtime() );
//	return ( (float) $usec + (float) $sec );
//}

//function find_environmental( $x ) {
//	return isset( $_SERVER[$x] ) ? $_SERVER[$x] : "";
//}

class UserAuth {
	var $fields;
	var $is_logged_in;
	var $permissions;
	var $is_banned;
	var $groups;

	function UserAuth() {
		global $config, $dbh;

		// First, the stupid stuff we do in every constructor
		$this->fields = array();
		$this->is_logged_in = false;
		$this->permissions = "";
		$this->is_banned = false;
		$this->groups = array();

		// Now, the real meat
		$id = $this->fetch_cookie( "ubbt_myid" );
		$pass = $this->fetch_cookie( "ubbt_pass" );

		if( $id == 0 ) {
			$this->is_logged_in = false;
			$this->fields = array(
				'USER_ID' => 1,
				'USER_DISPLAY_NAME' => "Anonymous",
			);
			$this->get_permissions();
			return;
		}

		$query = "
			SELECT	t1.USER_ID, t1.USER_DISPLAY_NAME, t1.USER_PASSWORD, t1.USER_MEMBERSHIP_LEVEL, t1.USER_IS_BANNED,
				t2.*
			FROM	{$config['TABLE_PREFIX']}USERS as t1,
				{$config['TABLE_PREFIX']}USER_PROFILE as t2
			WHERE	t1.USER_ID = t2.USER_ID AND t1.USER_ID = ?
		";

		$sth = $dbh->do_placeholder_query( $query, array( $id ), __LINE__, __FILE__ );
		$temp = $dbh->fetch_array( $sth );

		foreach( $temp as $k => $v ) {
			if( is_numeric( $k ) ) {
				unset( $temp[$k] );
			}
		}

		$this->fields =& $temp;
		
		$this->get_permissions();


		$key = $this->fetch_cookie( "ubbt_key" );
		$session = $this->fetch_cookie( "ubbt_mysess" );

		if( $this->fields['USER_SESSION_ID'] == $session ) {
			$this->is_logged_in = true;
			$this->check_ban();
			return;
		}

		if( $key == md5( $this->fields['USER_ID'] . $this->fields['USER_PASSWORD'] ) ) {
			srand( (double) ( microtime() * 1000000 ) );

			$new_session_id = md5( rand( 0, 32767 ) );

			$now = time() + ( $config['SERVER_TIME_OFFSET'] * 3600 );

			$query = "
				UPDATE	{$config['TABLE_PREFIX']}USERS
				SET	USER_SESSION_ID = ?
				WHERE	USER_ID = ?
			";

			$dbh->do_placeholder_query( $query, array( $new_session_id, $this->fields['USER_ID'] ), __LINE__, __FILE__ );

			$this->set_cookie( "ubbt_mysess", $new_session_id );
			$this->is_logged_in = true;

			$query = "
				UPDATE	{$config['TABLE_PREFIX']}USER_DATA
				SET	USER_LAST_VISIT_TIME = ?
				WHERE	USER_ID = ?
			";

			$dbh->do_placeholder_query( $query, array( $now, $this->fields['USER_ID'] ), __LINE__, __FILE__ );
			$this->check_ban();
			return;
		}
	}

	function check_ban() {
		// This will be especially long, since I refuse to require
		// an html object, since that makes this class pointless.
		global $config, $dbh;

		// First, is his status actually set to banned?
		if( $this->fields['USER_IS_BANNED'] ) {
			// This user was specifically banned, so find out for how long
			require_once( "/home/themeparknl/html/themepark.nl/ubb/libs/triggers.inc.php" );
			$free = trigger_ban_expiration();

			if( ! isset( $free[ $this->fields['USER_ID'] ] ) ) {
				$this->is_banned = true;
			}
		}

		$ip = $_SERVER['REMOTE_ADDR'];

		$query = "
			SELECT	COUNT( BANNED_HOST )
			FROM	{$config['TABLE_PREFIX']}BANNED_HOSTS
			WHERE	? LIKE BANNED_HOST
		";

		$sth = $dbh->do_placeholder_query( $query, array( $ip ), __LINE__, __FILE__ );
		list( $banned ) = $dbh->fetch_array( $sth );

		if( $banned ) {
			$this->is_banned = true;
		}
	}



	function fetch_cookie( $name ) {
		global $config;

		$k = $config['COOKIE_PREFIX'] . $name;

		return isset( $_COOKIE[$k] ) ? $_COOKIE[$k] : "";
	}

	function set_cookie( $name, $value ) {
		global $config;

		$name = $config['COOKIE_PREFIX'] . $name;
		$path = ( $config['COOKIE_PATH'] ? $config['COOKIE_PATH'] : ( $config['SEARCH_FRIENDLY_URLS'] ? "/" : "" ) );

		setcookie( $name, $value, 0, $path );

		if( $value ) {
			$_SESSION[$name] = $value;
		} else {
			unset( $_SESSION[$name] );
		}
	}

	function in_group( $id ) {
		return in_array( $id, $this->groups );
	}

	function build_permissions() {
		global $config, $dbh;

		if( is_array( $this->permissions ) ) {
			return true;
		}

		$this->permissions = array();

		$query = "
			SELECT	GROUP_ID
			FROM	{$config['TABLE_PREFIX']}USER_GROUPS
			WHERE	USER_ID = ?
		";
		
		$sth = $dbh->do_placeholder_query( $query, array( $this->fields['USER_ID'] ), __LINE__, __FILE__ );
		
		$groups = array();
		while( $x = $dbh->fetch_array( $sth ) ) {
			$groups[] = $x[0];
		}
		
		if( count( $groups ) == 0 ) {
			$groups[] = "4";
		}

		$this->groups = $groups;
		
		$query = "
			SELECT	*
			FROM	{$config['TABLE_PREFIX']}FORUM_PERMISSIONS
			WHERE	GROUP_ID in ( ? )
		";
		
		$sth = $dbh->do_placeholder_query( $query, array( $groups ), __LINE__, __FILE__ );
		
		while( $result = $dbh->fetch_array( $sth ) ) {
			if( ! $this->check_access( $result['FORUM_ID'], "read" ) ) {
				$this->set_access( $result['FORUM_ID'], "read", $result['FORUM_PERMISSION_CAN_READ'] );
			}
			
			if( ! $this->check_access( $result['FORUM_ID'], "topic" ) ) {
				$this->set_access( $result['FORUM_ID'], "topic", $result['FORUM_PERMISSION_CAN_CREATE_TOPIC'] );
			}
			
			if( ! $this->check_access( $result['FORUM_ID'], "reply" ) ) {
				$this->set_access( $result['FORUM_ID'], "reply", $result['FORUM_PERMISSION_CAN_CREATE_REPLY'] );
			}
		}
		
		$now = time();
		$cutoff = $now - ( 3600 * 4 );
		
		$query = "
			DELETE FROM	{$config['TABLE_PREFIX']}CACHED_PERMISSIONS
			WHERE		CACHED_TIMESTAMP < ?
		";
		
		$dbh->do_placeholder_query( $query, array( $cutoff ), __LINE__, __FILE__ );
		
		$query = "
			REPLACE INTO	{$config['TABLE_PREFIX']}CACHED_PERMISSIONS
					( USER_ID, CACHED_PERMISSION_DATA, CACHED_TIMESTAMP )
			VALUES		( ?, ?, ? )
		";
		
//		$dbh->do_placeholder_query( $query, array( $this->fields['USER_ID'], serialize( $this->permissions ), $now ), __LINE__, __FILE__ );
	}

	function get_permissions() {
		global $config, $dbh;

		// First, check to see if we have permissions cached
		$query = "
			SELECT CACHED_PERMISSION_DATA
			FROM {$config['TABLE_PREFIX']}CACHED_PERMISSIONS
			WHERE USER_ID = ?
		";

//		$sth = $dbh->do_placeholder_query( $query, array( $this->user_id ), __LINE__, __FILE__ );
		list( $data ) = $dbh->fetch_array( $sth );

		//if( ! $data ) {
			$this->build_permissions();
			return true;
//		}

		$this->permissions = unserialize( $data );
		return is_array( $this->permissions );
	}

	function check_access( $id, $type ) {
		return isset( $this->permissions[$id][$type] ) && $this->permissions[$id][$type] == 1;
	}
	
	function set_access( $id, $type, $val ) {
		if( ! isset( $this->permissions[$id] ) ) {
			$this->permissions[$id] = array();
		}
		
		$this->permissions[$id][$type] = $val;	
	}
}
?>




I am dropping this in as-is on my site. You'd need to adjust the include paths for your site.

Lots of stuff that game me errors just got commented out, I never did a cleanup and as I said, reading out forum permissions does not work anymore.


[Linked Image]
Re: User Authentication Class [Re: blaaskaak] #317659
11/10/2008 11:10 PM
11/10/2008 11:10 PM
Joined: Jun 2001
Posts: 56
I
intensity Offline
Power User
intensity  Offline
Power User
I
Joined: Jun 2001
Posts: 56
Sweet! It works! Thanks Yarp!

Re: User Authentication Class [Re: intensity] #318589
05/31/2010 2:23 PM
05/31/2010 2:23 PM
Joined: Oct 2004
Posts: 30
S
swebs Offline
User
swebs  Offline
User
S
Joined: Oct 2004
Posts: 30
thanks blaaskaak

Last edited by swebs; 05/31/2010 2:32 PM.
Re: User Authentication Class [Re: Ian Spence] #318745
04/14/2011 4:48 PM
04/14/2011 4:48 PM
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Gizmo Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Gizmo  Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Has anyone got this working under 7.5?


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Re: User Authentication Class [Re: Ian Spence] #318746
04/14/2011 5:38 PM
04/14/2011 5:38 PM
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Gizmo Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Gizmo  Offline

UBB.Dev / UBB.Wiki Owner
Time Lord
Joined: Jan 2000
Posts: 5,938
Portland, OR, USA
Played around and got yarp's version running on 7.5.6; not sure why it didn't like me at first lol...


UBB.Dev - Putting Dev into UBB.threads
Company: VNC Web Services - UBB.threads Scripts and Scripting, Install and Upgrade Services, Site and Server Maintenance.
Forums: A Gardeners Forum, Scouters World, and UGN Security
UBB.Threads: My UBB Themes, UBB.Sitemaps
Sponsored Links
Page 2 of 2 1 2

Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with, and recommend, the following Web Hosts:
· Stable Host
· Blue Host
· Interserver.net
Visit Us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,170
Joined: July 2001
Show All Member Profiles 
Forum Statistics
Forums64
Topics37,448
Posts293,484
Members13,793
Most Online1,498
Mar 17th, 2017
Top Posters(All Time)
AllenAyres 25,587
JoshPet 11,330
Rick 8,373
LK 7,396
Lord Dexter 6,503
Gizmo 5,938
Greg Hard 5,533
Top Posters(30 Days)
isaac 4
Today's Statistics
Currently Online 660
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 17
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2018 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 7.6.2
(Preview build 20180611.dev)
Page Time: 0.096s Queries: 16 (0.019s) Memory: 3.3662 MB (Peak: 3.6602 MB) Zlib enabled. Server Time: 2018-06-18 11:22:12 UTC