Skip to content

Commit

Permalink
2023-01-19 09:30 - v2.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisOuellet committed Jan 19, 2023
1 parent f2b9154 commit b087730
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.6
2.3.7
19 changes: 18 additions & 1 deletion src/phpAUTH.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public function setCookieOptions($options = null){
$defaults = [
'secure' => true,
'httponly' => false,
'path' => '/',
'domain' => $this->Domain,
'samesite' => 'Strict',
'expires' => time() + 60*60*24*30,
Expand All @@ -155,6 +156,11 @@ public function setCookieOptions($options = null){
$defaults[$key] = $value;
}
}
$defaults['expires'] = intval($defaults['expires']);
$defaults['path'] = strval($defaults['path']);
$defaults['domain'] = strval($defaults['domain']);
$defaults['secure'] = boolval($defaults['secure']);
$defaults['httponly'] = boolval($defaults['httponly']);
$this->CookieOptions = $defaults;
}

Expand All @@ -165,6 +171,11 @@ public function setCookie($name, $data = null, $options = []){
$defaults[$key] = $value;
}
}
$defaults['expires'] = intval($defaults['expires']);
$defaults['path'] = strval($defaults['path']);
$defaults['domain'] = strval($defaults['domain']);
$defaults['secure'] = boolval($defaults['secure']);
$defaults['httponly'] = boolval($defaults['httponly']);
if($data == null){ $data = ''; }
if(is_array($data)){ $data = json_encode($data,JSON_UNESCAPED_SLASHES); }
setcookie($name, $data, $defaults);
Expand Down Expand Up @@ -498,7 +509,13 @@ public function getUser($field = null){
$this->User['sessionID'] = session_id();
$this->Database->update("UPDATE auth_users SET sessionID = ? WHERE username = ?", [$this->User['sessionID'],$this->User['username']]);
if($this->User['sessionID'] != ''){
$this->Database->insert("INSERT INTO auth_sessions (sessionID,username,userAgent,userBrowser,userIP,userData) VALUES (?,?,?,?,?,?)", [$this->User['sessionID'],$this->User['username'],$_SERVER['HTTP_USER_AGENT'],$this->getClientBrowser(),$this->getClientIP(),json_encode($this->User)]);
$sessions = $this->Database->select("SELECT * FROM auth_sessions WHERE sessionID = ?", [$this->User['sessionID']]);
if(count($sessions) > 0){
$session = $sessions[0];
$this->Database->update("UPDATE auth_sessions SET username = ?, userAgent = ?, userBrowser = ?, userIP = ?, userData = ? WHERE id = ?", [$this->User['username'],$_SERVER['HTTP_USER_AGENT'],$this->getClientBrowser(),$this->getClientIP(),json_encode($this->User),$session['id']]);
} else {
$this->Database->insert("INSERT INTO auth_sessions (sessionID,username,userAgent,userBrowser,userIP,userData) VALUES (?,?,?,?,?,?)", [$this->User['sessionID'],$this->User['username'],$_SERVER['HTTP_USER_AGENT'],$this->getClientBrowser(),$this->getClientIP(),json_encode($this->User)]);
}
if(!isset($_COOKIE['sessionID'])){ $this->setCookie( "sessionID", $this->User['sessionID'], ['expires' => $this->Authentication->getAuth('timestamp')] ); }
if(!isset($_COOKIE['timestamp'])){ $this->setCookie( "timestamp", $this->Authentication->getAuth('timestamp'), ['expires' => $this->Authentication->getAuth('timestamp')] ); }
$_SESSION['sessionID'] = $this->User['sessionID'];
Expand Down

0 comments on commit b087730

Please sign in to comment.