Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Feb 2007
Posts: 329
Yarp™
Yarp™
Offline
Joined: Feb 2007
Posts: 329
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.

Sponsored Links
Entire Thread
Subject Posted By Posted
User Authentication Class Ian Spence 01/19/2007 10:59 PM
Re: User Authentication Class AllenAyres 01/20/2007 1:00 AM
Re: User Authentication Class Gizmo 01/20/2007 1:59 AM
Re: User Authentication Class Calpy 01/20/2007 3:03 AM
Re: User Authentication Class AllenAyres 01/20/2007 3:29 AM
Re: User Authentication Class Gizmo 01/20/2007 3:44 AM
Re: User Authentication Class Calpy 01/20/2007 3:57 AM
Re: User Authentication Class Gizmo 01/20/2007 4:05 AM
Re: User Authentication Class JoshPet 01/20/2007 7:36 AM
Re: User Authentication Class blaaskaak 03/14/2007 4:08 PM
Re: User Authentication Class blaaskaak 04/17/2007 6:15 PM
Re: User Authentication Class Ian Spence 04/19/2007 11:16 PM
Re: User Authentication Class blaaskaak 05/21/2007 11:26 PM
Re: User Authentication Class Mark_S 08/09/2007 2:13 AM
Re: User Authentication Class Mark_S 08/10/2007 1:34 PM
Re: User Authentication Class AllenAyres 08/10/2007 8:36 PM
Re: User Authentication Class Mark_S 08/10/2007 9:01 PM
Re: User Authentication Class Mark_S 08/11/2007 2:09 PM
Re: User Authentication Class AllenAyres 08/11/2007 3:32 PM
Re: User Authentication Class Ian Spence 08/12/2007 3:49 AM
Re: User Authentication Class Gizmo 08/12/2007 5:46 AM
Re: User Authentication Class AllenAyres 08/13/2007 7:20 AM
Re: User Authentication Class Mark_S 08/16/2007 10:15 PM
Re: User Authentication Class sirdude 08/16/2007 10:23 PM
Re: User Authentication Class Mark_S 08/19/2007 11:13 AM
Re: User Authentication Class Mark_S 02/19/2008 10:39 PM
Chat Profile:Need convert user_name to user_number curiousguy 04/07/2008 10:31 AM
Re: Chat Profile:Need convert user_name to user_number blaaskaak 04/07/2008 6:38 PM
Re: Chat Profile:Need convert user_name to user_number AllenAyres 04/08/2008 4:09 PM
Re: Chat Profile:Need convert user_name to user_number blaaskaak 05/12/2008 2:46 PM
Re: User Authentication Class blaaskaak 05/12/2008 7:43 PM
Re: User Authentication Class swebs 07/19/2008 1:19 AM
Re: User Authentication Class Myke 07/21/2008 3:54 PM
Re: User Authentication Class swebs 07/21/2008 8:44 PM
Re: User Authentication Class Gizmo 07/22/2008 2:07 AM
Re: User Authentication Class intensity 11/06/2008 9:00 AM
Re: User Authentication Class Gizmo 11/06/2008 3:02 PM
Re: User Authentication Class intensity 11/06/2008 6:58 PM
Re: User Authentication Class blaaskaak 11/08/2008 12:59 PM
Re: User Authentication Class blaaskaak 11/09/2008 12:04 PM
Re: User Authentication Class intensity 11/11/2008 6:10 AM
Re: User Authentication Class swebs 05/31/2010 9:23 PM
Re: User Authentication Class Myke 07/08/2008 12:53 PM
Re: User Authentication Class Gizmo 07/08/2008 4:04 PM
Re: User Authentication Class blaaskaak 07/09/2008 12:40 AM
Re: User Authentication Class sirdude 07/09/2008 1:11 AM
Re: User Authentication Class swebs 07/18/2008 12:57 AM
Re: User Authentication Class sirdude 07/18/2008 6:50 PM
Re: User Authentication Class Gizmo 04/14/2011 11:48 PM
Re: User Authentication Class Gizmo 04/15/2011 12:38 AM

Link Copied to Clipboard
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
bluehost
InterServer
Visit us on Facebook
Member Spotlight
JAISP
JAISP
PA
Posts: 449
Joined: February 2008
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)