improve: nextcloud: set 'smremember' cookie if 'sign_me_auto' is set to 'DefaultOn' when using 'snappymail-autologin*', otherwise nextcloud users need to re-login when the browser is re-opened.

This commit is contained in:
Sergey Mosin 2023-08-16 10:42:17 -04:00
parent 35cd354353
commit 79c8281a6b
4 changed files with 16 additions and 6 deletions

View file

@ -86,7 +86,8 @@ class Application extends App implements IBootstrap
// https://github.com/nextcloud/server/issues/36083#issuecomment-1387370634
// \OC::$server->getSession()['snappymail-password'] = '';
SnappyMailHelper::loadApp();
\RainLoop\Api::Actions()->Logout(true);
// \RainLoop\Api::Actions()->Logout(true);
\RainLoop\Api::Actions()->DoLogout();
});
// https://github.com/nextcloud/impersonate/issues/179

View file

@ -80,7 +80,9 @@ class SnappyMailHelper
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
try {
$oActions->Logger()->AddSecret($aCredentials[2]);
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false);
$bSignMe = $oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DEFAULT_OFF) === \RainLoop\Enumerations\SignMeType::DEFAULT_ON;
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], $bSignMe);
if ($oAccount) {
$oActions->Plugins()->RunHook('login.success', array($oAccount));
$oActions->SetAuthToken($oAccount);

View file

@ -139,7 +139,14 @@ trait UserAuth
$this->imapConnect($oAccount, true);
if ($bMainAccount) {
$bSignMe && $this->SetSignMeToken($oAccount);
if($bSignMe){
// SetAuthToken token needs to be called before SetSignMeToken
// because $_COOKIE['smctoken'] is used by Crypt::Passphrase.
// If the $_COOKIE['smctoken'] is not set then SetSignMeToken
// throws an exception
$this->SetAuthToken($oAccount);
$this->SetSignMeToken($oAccount);
}
$this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true');
}

View file

@ -83,7 +83,7 @@ class Cookies
if ($cookie_remove) {
\header_remove('Set-Cookie');
foreach ($cookies as $cookie) {
\header($cookie);
\header($cookie,false);
}
}
@ -118,14 +118,14 @@ class Cookies
foreach (\str_split($sValue, $iMaxSize) as $i => $sPart) {
$sCookieName = $i ? "{$sName}~{$i}" : $sName;
Log::debug('COOKIE', "set {$sCookieName}");
static::_set($sCookieName, $sPart, $iExpire);
static::_set($sCookieName, $sPart, $iExpire, $httponly);
}
// Delete unused old 4K split cookie parts
foreach (\array_keys($_COOKIE) as $sCookieName) {
$aSplit = \explode('~', $sCookieName);
if (isset($aSplit[1]) && $aSplit[0] == $sName && $aSplit[1] > $i) {
Log::debug('COOKIE', "unset {$sCookieName}");
static::_set($sCookieName, '', 0);
static::_set($sCookieName, '', 0, $httponly);
}
}
}