Remove cookie on unsubscribe

This commit is contained in:
2020-04-14 20:27:56 +02:00
parent 73713d477b
commit f36c1cf74a

View File

@@ -7,7 +7,7 @@ class User extends PhpObject {
//Cookie //Cookie
const COOKIE_ID_USER = 'subscriber'; const COOKIE_ID_USER = 'subscriber';
const COOKIE_DURATION = 60 * 60 * 24 * 365; //1 year
/** /**
* Database Handle * Database Handle
* @var Db * @var Db
@@ -56,7 +56,7 @@ class User extends PhpObject {
//Set Cookie (valid 1 year) //Set Cookie (valid 1 year)
if($bSuccess) { if($bSuccess) {
$this->setUserId($iUserId); $this->setUserId($iUserId);
$this->updateCookie(); $this->updateCookie(self::COOKIE_DURATION);
} }
return Spot::getResult($bSuccess, $sDesc); return Spot::getResult($bSuccess, $sDesc);
@@ -71,6 +71,7 @@ class User extends PhpObject {
if($iUserId==0) $sDesc = 'lang:error_commit_db'; if($iUserId==0) $sDesc = 'lang:error_commit_db';
else { else {
$sDesc = 'lang:nl_unsubscribed'; $sDesc = 'lang:nl_unsubscribed';
$this->updateCookie(-60 * 60); //Set Cookie in the past, deleting it
$bSuccess = true; $bSuccess = true;
} }
} }
@@ -88,7 +89,7 @@ class User extends PhpObject {
$this->setUserId($_COOKIE[self::COOKIE_ID_USER]); $this->setUserId($_COOKIE[self::COOKIE_ID_USER]);
//Extend cookie life //Extend cookie life
if($this->iUserId > 0) $this->updateCookie(); if($this->iUserId > 0) $this->updateCookie(self::COOKIE_DURATION);
} }
} }
@@ -121,7 +122,7 @@ class User extends PhpObject {
return $this->oDb->selectRows($asInfo); return $this->oDb->selectRows($asInfo);
} }
private function updateCookie() { private function updateCookie($iDeltaTime) {
setcookie(self::COOKIE_ID_USER, $this->iUserId, time() + 60 * 60 * 24 * 365); setcookie(self::COOKIE_ID_USER, ($iDeltaTime < 0)?'':$this->iUserId, time() + $iDeltaTime);
} }
} }