commit 877b6b901a316d0e3f7a229ec37c9f4efeb77a57
parent e4e3229b130c63cab94f0c307a04f07fc5cef03c
Author: Jan Dankert <develop@jandankert.de>
Date: Fri, 23 Aug 2019 22:18:33 +0200
Fix: Beim Löschen des Benutzers alle Logintoken löschen; Beim Abmelden den aktuellen Logintoken löschen.
Diffstat:
2 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php
@@ -866,7 +866,7 @@ class LoginAction extends Action
/**
* Benutzer meldet sich ab.
*/
- function logoutPost()
+ public function logoutPost()
{
global $conf;
@@ -877,8 +877,6 @@ class LoginAction extends Action
if ( config()->subset('security')->is('renew_session_logout',false) )
$this->recreateSession();
- session_unset();
-
if ( @$conf['theme']['compiler']['compile_at_logout'] )
{
foreach( $conf['action'] as $actionName => $actionConfig )
@@ -903,9 +901,19 @@ class LoginAction extends Action
// Login-Token löschen:
// Wenn der Benutzer sich abmelden will, dann soll auch die automatische
// Anmeldung deaktiviert werden.
+
+ // Bestehendes Login-Token aus dem Cookie lesen und aus der Datenbank löschen.
+ list( $selector,$token ) = array_pad( explode('.',$_COOKIE['or_token']),2,'');
+
+ if ( $selector )
+ $this->currentUser->deleteLoginToken( $selector );
+
+ // Cookie mit Logintoken löschen.
$this->setCookie('or_token' ,null );
-
- // Umleiten auf eine definierte URL.s
+
+ session_unset();
+
+ // Umleiten auf eine definierte URL.s
$redirect_url = @$conf['security']['logout']['redirect_url'];
if ( !empty($redirect_url) )
diff --git a/modules/cms-core/model/User.class.php b/modules/cms-core/model/User.class.php
@@ -204,8 +204,8 @@ SQL
*/
function createNewLoginToken()
{
- $selector = Password::randomHexString(48);
- $token = Password::randomHexString(48);
+ $selector = Password::randomHexString(24);
+ $token = Password::randomHexString(24);
$tokenHash = Password::hash($token,Password::ALGO_SHA1);
@@ -217,7 +217,7 @@ SQL
VALUES( {id},{userid},{selector},{token},{token_algo},{expires},{create_date},{platform},{name} )
SQL
);
- $expirationPeriod = Conf()->subset('user')->subset('security')->get('token_expires_after_days',730);
+ $expirationPeriodDays = Conf()->subset('user')->subset('security')->get('token_expires_after_days',730);
$stmt->setInt( 'id' ,++$count );
$stmt->setInt( 'userid' ,$this->userid );
@@ -226,7 +226,7 @@ SQL
$stmt->setString( 'token' ,$tokenHash );
$stmt->setInt ( 'token_algo' ,Password::ALGO_SHA1 );
- $stmt->setInt( 'expires' ,time() + $expirationPeriod );
+ $stmt->setInt( 'expires' ,time() + ($expirationPeriodDays*24*60*60) );
$stmt->setInt( 'create_date',time() );
$browser = new \Browser();
@@ -239,7 +239,22 @@ SQL
}
- /**
+ /**
+ * Ermittelt zu diesem Benutzer den Login-Token.
+ */
+ function deleteLoginToken( $selector )
+ {
+ $stmt = db()->sql( <<<SQL
+ DELETE FROM {{auth}}
+ WHERE selector = {selector}
+SQL
+ );
+ $stmt->setString('selector',$selector );
+ $stmt->execute();
+ }
+
+
+ /**
* Lesen Benutzer aus der Datenbank.
*/
public function load()
@@ -516,7 +531,15 @@ SQL
$sql->setInt ('userid',$this->userid );
$sql->query();
- // Benutzer loeschen
+ $stmt = db()->sql( <<<SQL
+ DELETE FROM {{auth}}
+ WHERE userid={userid}
+SQL
+ );
+ $stmt->setInt ('userid',$this->userid );
+ $stmt->execute();
+
+ // Benutzer loeschen
$sql = $db->sql( 'DELETE FROM {{user}} '.
'WHERE id={userid}' );
$sql->setInt ('userid',$this->userid );