phpUserTrack
[
class tree: phpUserTrack
] [
index: phpUserTrack
] [
all elements
]
ChangeLog
INSTALL
Todo List
Packages:
phpUserTrack
Source for file liblogin.php
Documentation is available at
liblogin.php
<?php
require_once
(
'libdb.php'
)
;
define
(
"ADMIN_NAME"
,
"Admin"
)
;
define
(
"GUEST_NAME"
,
"Guest"
)
;
define
(
"ADMIN_LEVEL"
,
9
)
;
define
(
"USER_LEVEL"
,
1
)
;
define
(
"GUEST_LEVEL"
,
0
)
;
class
LoginException
extends
Exception
{
function
__construct
(
$message
=
null
,
$code
=
0
)
{
parent
::
__construct
(
$message
,
$code
)
;
}
}
class
login
extends
phpusertrack_db
{
private
$_username
;
//Username given on sign-up
private
$_uid
;
//Random value generated on current login
private
$_userlevel
=
GUEST_LEVEL
;
//The level to which the user pertains
private
$_isLoggedIn
=
false
;
//True if user is logged in, false otherwise
private
$_userinfo
=
array
(
)
;
//The array holding all user info
function
login
(
$checkLogin
=
false
)
{
global
$conf
;
global
$smarty
;
if
(
isset
(
$_SESSION
[
'uid'
]
))
{
$sql
=
'select * from phpusertrack_users where id=\''
.
$_SESSION
[
'uid'
]
.
'\''
;
$dat
=
$this
->
_query
(
$sql
)
;
$this
->
_username
=
$dat
[
0
]
[
'username'
]
;
$this
->
_uid
=
$dat
[
0
]
[
'id'
]
;
$this
->
_userlevel
=
$dat
[
0
]
[
'userlevel'
]
;
$_SESSION
[
'uid'
]
=
$this
->
_uid
;
$this
->
_isLoggedIn
=
true
;
$smarty
->
assign
(
'userlevel'
,
$this
->
_userlevel
)
;
}
else
if
(
$conf
[
'allowanonymous'
]
)
{
$this
->
_username
=
GUEST_NAME
;
$this
->
_isLoggedIn
=
true
;
$smarty
->
assign
(
'userlevel'
,
$this
->
_userlevel
)
;
}
else
{
$this
->
_isLoggedIn
=
false
;
}
if
(
$checkLogin
)
{
$this
->
checkLogin
(
)
;
}
}
function
checkLogin
(
)
{
if
(
!
$this
->
_isLoggedIn
)
{
throw
new
LoginException
(
)
;
}
}
function
submit_login
(
$username
,
$password
)
{
try
{
$sql
=
'select * from phpusertrack_users where username=\''
.
$username
.
'\' and password=\''
.
md5
(
$password
)
.
'\' limit 1'
;
$dat
=
$this
->
_query
(
$sql
)
;
if
(
count
(
$dat
)
>
0
)
{
$this
->
_username
=
$dat
[
0
]
[
'username'
]
;
$this
->
_uid
=
$dat
[
0
]
[
'id'
]
;
$this
->
_isLoggedIn
=
true
;
$this
->
_userlevel
=
$dat
[
0
]
[
'userlevel'
]
;
$_SESSION
[
'uid'
]
=
$this
->
_uid
;
}
return
$this
->
isLoggedIn
(
)
;
}
catch
(
Exception
$e
)
{
throw
new
Exception
(
$this
->
_db
->
toString
(
))
;
}
}
function
isLoggedIn
(
)
{
return
$this
->
_isLoggedIn
;
}
function
isGuest
(
)
{
if
(
$this
->
_userlevel
==
GUEST_LEVEL
)
{
return
true
;
}
else
{
return
false
;
}
}
}
/* class login extends phpusertrack_db {
private $_username; //Username given on sign-up
private $_uid; //Random value generated on current login
private $_userlevel = GUEST_LEVEL; //The level to which the user pertains
private $_isLoggedIn = false; //True if user is logged in, false otherwise
private $_userinfo = array(); //The array holding all user info
function login() {
global $conf;
$this->_isLoggedIn = $this->checkLogin();
die;
if(!$this->_isLoggedIn){
if ($conf['allowanonymous']) {
$this->_isLoggedIn = true;
$this->_userlevel = 0;
return true;
} else {
$this->_isLoggedIn = false;
return false;
}
}
return true;
}
function checkLogin(){
global $smarty;
if (isset($_SESSION['uid'])) {
try {
$this->_connect();
$sql = 'select * from phpusertrack_users where id=\'' . $_SESSION['uid'] . '\'';
$dat = $this->_query($sql);
$this->_username = $dat[0]['username'];
$this->_uid = $dat[0]['id'];
$this->_isLoggedIn = true;
$this->_userlevel = $dat[0]['userlevel'];
$_SESSION['uid'] = $this->_uid;
} catch (Exception $e) {
throw new LoginException($this->_db->toString());
}
} else if (!$conf['allowanonymous']) {
throw new LoginException();
}
$smarty->assign('userlevel', $this->_userlevel);
return $this->isLoggedIn();
}
function isLoggedIn() {
return $this->_isLoggedIn;
}
function isGuest() {
if ($this->_userlevel == 0) {
return true;
} else {
return false;
}
}
function submit_login($username, $password) {
try {
$this->_connect();
$sql = 'select * from phpusertrack_users where username=\'' . $username . '\' and password=\'' . md5($password) . '\' limit 1';
$dat = $this->_query($sql);
if (count($dat) > 0) {
$this->_username = $dat[0]['username'];
$this->_uid = $dat[0]['id'];
$this->_isLoggedIn = true;
$this->_userlevel = $dat[0]['userlevel'];
$_SESSION['uid'] = $this->_uid;
}
return $this->isLoggedIn();
} catch (Exception $e) {
throw new Exception($this->_db->toString());
}
}
} */
?>
Documentation generated on Tue, 06 Nov 2007 09:22:04 -0800 by
phpDocumentor 1.4.0a2