adding PHP Excel library
This commit is contained in:
36
inc/auth.php
36
inc/auth.php
@@ -7,6 +7,11 @@ class Auth extends PhpObject
|
||||
const TOKEN_SEP = '|';
|
||||
const USER_COOKIE_PASS = 'checksum';
|
||||
|
||||
const MEMBER_INACTIVE = 0;
|
||||
const MEMBER_ACTIVE = 1;
|
||||
const CLEARANCE_MEMBER = 1;
|
||||
const CLEARANCE_ADMIN = 9;
|
||||
|
||||
/**
|
||||
* Database Connection
|
||||
* @var MySqlManager
|
||||
@@ -15,7 +20,7 @@ class Auth extends PhpObject
|
||||
private $iUserId;
|
||||
private $sApiKey;
|
||||
|
||||
public function __construct($oMySql, $sApiKey='', $bAutoLogin=true)
|
||||
public function __construct(MySqlManager $oMySql, $sApiKey='', $bAutoLogin=true)
|
||||
{
|
||||
$this->oMySql = $oMySql;
|
||||
$this->setUserId(0);
|
||||
@@ -40,6 +45,7 @@ class Auth extends PhpObject
|
||||
|
||||
public function logMeIn($sToken)
|
||||
{
|
||||
$this->oMySql->setTrace(true);
|
||||
$sDesc = '';
|
||||
if($sToken!='')
|
||||
{
|
||||
@@ -47,12 +53,12 @@ class Auth extends PhpObject
|
||||
$sPassToken = substr(strstr($sToken, self::TOKEN_SEP), strlen(self::TOKEN_SEP));
|
||||
if($sLoginToken!='' && $sPassToken!='')
|
||||
{
|
||||
$asEmpl = $this->oMySql->selectRow(MyThoughts::USER_TABLE, array("MD5(".MySqlManager::getText(MyThoughts::USER_TABLE).")"=>$sLoginToken));
|
||||
$asEmpl = $this->oMySql->selectRow(Pedidor::USER_TABLE, array("MD5(".MySqlManager::getText(Pedidor::USER_TABLE).")"=>$sLoginToken));
|
||||
if(!empty($asEmpl))
|
||||
{
|
||||
if(self::CheckPassword($sPassToken, $asEmpl['pass']))
|
||||
{
|
||||
$this->setUserId($asEmpl[MySqlManager::getId(MyThoughts::USER_TABLE)]);
|
||||
$this->setUserId($asEmpl[MySqlManager::getId(Pedidor::USER_TABLE)]);
|
||||
$this->resetAuthCookie($this->getUserId());
|
||||
}
|
||||
else $sDesc = 'wrong password';
|
||||
@@ -63,7 +69,7 @@ class Auth extends PhpObject
|
||||
}
|
||||
else $sDesc = 'no credentials has been received by the server';
|
||||
|
||||
return MyThoughts::getJsonResult($this->isLoggedIn(), $sDesc);
|
||||
return Pedidor::getJsonResult($this->isLoggedIn(), $sDesc);
|
||||
}
|
||||
|
||||
public function autoLogIn()
|
||||
@@ -74,17 +80,17 @@ class Auth extends PhpObject
|
||||
$iUserId = addslashes(strstr($sCookie, self::TOKEN_SEP, true));
|
||||
$sCookie = substr(strstr($sCookie, self::TOKEN_SEP), strlen(self::TOKEN_SEP));
|
||||
|
||||
$asEmpl = $this->oMySql->selectRow(MyThoughts::USER_TABLE, array(MySqlManager::getId(MyThoughts::USER_TABLE)=>$iUserId));
|
||||
$asEmpl = $this->oMySql->selectRow(Pedidor::USER_TABLE, array(MySqlManager::getId(Pedidor::USER_TABLE)=>$iUserId));
|
||||
if(!empty($asEmpl))
|
||||
{
|
||||
if($sCookie==$asEmpl['cookie'])
|
||||
{
|
||||
$this->setUserId($asEmpl[MySqlManager::getId(MyThoughts::USER_TABLE)]);
|
||||
$this->setUserId($asEmpl[MySqlManager::getId(Pedidor::USER_TABLE)]);
|
||||
|
||||
//Reset pass once a day
|
||||
if(mb_substr($asEmpl['led'], 0, 10) != date('Y-m-d')) $this->resetAuthCookie($this->getUserId());
|
||||
}
|
||||
else $this->addError('token corrompu pour le user '.$asEmpl[MySqlManager::getId(MyThoughts::USER_TABLE)]);
|
||||
else $this->addError('token corrompu pour le user '.$asEmpl[MySqlManager::getId(Pedidor::USER_TABLE)]);
|
||||
}
|
||||
else $this->addError('Utilisateur '.$iUserId.' inconnu');
|
||||
}
|
||||
@@ -93,11 +99,12 @@ class Auth extends PhpObject
|
||||
public function addUser($sSafeNickName, $sNickName, $bLogMeIn=false)
|
||||
{
|
||||
$sPass = self::HashPassword(self::getLoginToken($sSafeNickName));
|
||||
$bExist = $this->oMySql->pingValue(MyThoughts::USER_TABLE, array(MySqlManager::getText(MyThoughts::USER_TABLE)=>$sSafeNickName));
|
||||
$bExist = $this->oMySql->pingValue(Pedidor::USER_TABLE, array(MySqlManager::getText(Pedidor::USER_TABLE)=>$sSafeNickName));
|
||||
if($bExist) return -1;
|
||||
else
|
||||
{
|
||||
$iUserId = $this->oMySql->insertRow(MyThoughts::USER_TABLE, array(MySqlManager::getText(MyThoughts::USER_TABLE)=>$sSafeNickName, 'nickname'=>$sNickName));
|
||||
$asUserInfo = array(MySqlManager::getText(Pedidor::USER_TABLE)=>$sSafeNickName, 'active'=>self::MEMBER_ACTIVE, 'clearance'=>self::CLEARANCE_MEMBER);
|
||||
$iUserId = $this->oMySql->insertRow(Pedidor::USER_TABLE, $asUserInfo);
|
||||
if($iUserId>0)
|
||||
{
|
||||
$this->resetPass($iUserId);
|
||||
@@ -115,17 +122,17 @@ class Auth extends PhpObject
|
||||
|
||||
private function resetPass($iUserId=0)
|
||||
{
|
||||
$sUserIdCol = MySqlManager::getId(MyThoughts::USER_TABLE);
|
||||
$sUserTextCol = MySqlManager::getText(MyThoughts::USER_TABLE);
|
||||
$sUserIdCol = MySqlManager::getId(Pedidor::USER_TABLE);
|
||||
$sUserTextCol = MySqlManager::getText(Pedidor::USER_TABLE);
|
||||
|
||||
$asInfo = array('select'=>array($sUserIdCol, $sUserTextCol), 'from'=>MyThoughts::USER_TABLE);
|
||||
$asInfo = array('select'=>array($sUserIdCol, $sUserTextCol), 'from'=>Pedidor::USER_TABLE);
|
||||
if($iUserId>0) $asInfo['constraint'] = array($sUserIdCol=>$iUserId);
|
||||
|
||||
$asUsers = $this->oMySql->selectRows($asInfo);
|
||||
foreach($asUsers as $asUser)
|
||||
{
|
||||
$sToken = self::HashPassword(self::getLoginToken($asUser[$sUserTextCol]));
|
||||
$this->oMySql->updateRow(MyThoughts::USER_TABLE, array(MySqlManager::getId(MyThoughts::USER_TABLE)=>$asUser[$sUserIdCol]), array('pass'=>$sToken));
|
||||
$this->oMySql->updateRow(Pedidor::USER_TABLE, array(MySqlManager::getId(Pedidor::USER_TABLE)=>$asUser[$sUserIdCol]), array('pass'=>$sToken));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +149,7 @@ class Auth extends PhpObject
|
||||
{
|
||||
$sNewPass = self::getAuthCookie($iUserId);
|
||||
$iTimeLimit = time()+60*60*24*30;
|
||||
//mysqli_query($con, "UPDATE EMPLOYEE SET COOKIE = '".addslashes($sNewPass)."' WHERE ID = ".$iUserId);
|
||||
$this->oMySql->updateRow(MyThoughts::USER_TABLE, array(MySqlManager::getId(MyThoughts::USER_TABLE)=>$iUserId), array("cookie"=>$sNewPass));
|
||||
$this->oMySql->updateRow(Pedidor::USER_TABLE, array(MySqlManager::getId(Pedidor::USER_TABLE)=>$iUserId), array("cookie"=>$sNewPass));
|
||||
setcookie(self::USER_COOKIE_PASS, $iUserId.self::TOKEN_SEP.$sNewPass, $iTimeLimit);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user