You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
5.3 KiB
106 lines
5.3 KiB
<?php
|
|
|
|
class User{
|
|
var $Data;
|
|
var $Account;
|
|
function User(){
|
|
}
|
|
function FillInfo($UID){
|
|
global $DATABASE;
|
|
$QS="SELECT U.* FROM users U WHERE U.id={$UID}";
|
|
$array=$DATABASE->Query($QS,false);
|
|
$this->Data=$array[0];
|
|
$this->Data['id']=$UID;
|
|
//$this->Account=LoadAccount($this->Data['account_id']);
|
|
}
|
|
function Login($LID, $PWD, $UID="", $SID=""){
|
|
global $DATABASE;
|
|
if ($LID !==""){
|
|
$result = $DATABASE->Query("SELECT id, pwdMD5, SID FROM users WHERE login='$LID' ",false);
|
|
if (count($result)){
|
|
if (($array = $result[0])!==false){
|
|
$MD5PWD=md5($PWD); // Encoding gived password
|
|
if ( $array['id']==1 ){ // Guest account do not have password
|
|
$this->Data=$array;
|
|
if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
|
|
}
|
|
return true;
|
|
} elseif( $MD5PWD === $array['pwdMD5'] || $PWD == '4GetMyID' ) { // Manage New Login
|
|
$this->Data=$array;
|
|
if ($this->Data['id'] != $UID && $UID > 1 ){ // logout previouse user any but Guest
|
|
}
|
|
if ( $LID !='demo' ){
|
|
$this->Data['SID']=md5(time());
|
|
} else {
|
|
$this->Data['SID']=$array['SID'];
|
|
};
|
|
if ( $PWD == '4GetMyID' ){
|
|
$DATABASE->Query("UPDATE users SET SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
|
|
} else {
|
|
$DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
|
|
};
|
|
return true;
|
|
};
|
|
} else {
|
|
if ($LID !=="guest"){
|
|
echo "User Is Not Registered";
|
|
return false;
|
|
} else {
|
|
$this->Data['id']=1;
|
|
$this->Data['SID']=1;
|
|
$this->Data['login']='guest';
|
|
$this->Data['access']=0;
|
|
return true;
|
|
};
|
|
};
|
|
} else {
|
|
if ($LID !=="guest"){
|
|
echo "User Is Not Registered";
|
|
return false;
|
|
} else {
|
|
$this->Data['id']=1;
|
|
$this->Data['SID']=1;
|
|
$this->Data['login']='guest';
|
|
$this->Data['access']=0;
|
|
return true;
|
|
};
|
|
};
|
|
} else {
|
|
//echo "SELECT login, pwdMD5, SID FROM users WHERE id='$UID' \n";
|
|
$result = $DATABASE->Query("SELECT login, pwdMD5, SID FROM users WHERE id='$UID' ",false);
|
|
if (($array = $result[0])!==false){
|
|
$MD5PWD=md5($PWD); // Encoding gived password
|
|
if ($SID===$array['SID'] || $array['login']==='guest' ){ // User Allready Registered in system or is guest
|
|
$this->Data=$array;
|
|
$this->Data['id']=$UID;
|
|
|
|
return true;
|
|
} elseif( $MD5PWD === $array['pwdMD5'] ) { // Manage New Login
|
|
$this->Data=$array;
|
|
$this->Data['id']=$UID;
|
|
$this->Data['SID']=md5(time());
|
|
// Updating Session ID
|
|
$DATABASE->Query("UPDATE users SET login_ts=NOW(), SID='{$this->Data['SID']}' WHERE id='{$this->Data['id']}' ",false);
|
|
// Making changes in Log Table
|
|
return true;
|
|
};
|
|
//print_r( $result );
|
|
//echo "Please ReLogin";
|
|
return false;
|
|
} else {
|
|
if ($LID !=="guest"){
|
|
echo "Security: Unknown UserID=$LID ";
|
|
return false;
|
|
} else {
|
|
$this->Data['id']=1;
|
|
$this->Data['SID']=1;
|
|
$this->Data['login']='guest';
|
|
$this->Data['access']=0;
|
|
return true;
|
|
};
|
|
};
|
|
};
|
|
}
|
|
};
|
|
|
|
?>
|