mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Other solutions for nextcloud auto login #1247 due to a TOTP conflict
This commit is contained in:
parent
31d50cf67e
commit
26b7abf893
6 changed files with 17 additions and 18 deletions
|
|
@ -80,12 +80,13 @@ class SnappyMailHelper
|
||||||
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
||||||
try {
|
try {
|
||||||
$oActions->Logger()->AddSecret($aCredentials[2]);
|
$oActions->Logger()->AddSecret($aCredentials[2]);
|
||||||
|
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
|
||||||
$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) {
|
if ($oAccount) {
|
||||||
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
||||||
$oActions->SetAuthToken($oAccount);
|
$oActions->SetAuthToken($oAccount);
|
||||||
|
if ($oConfig->Get('login', 'sign_me_auto', \RainLoop\Enumerations\SignMeType::DEFAULT_OFF) === \RainLoop\Enumerations\SignMeType::DEFAULT_ON) {
|
||||||
|
$oActions->SetSignMeToken($oAccount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// Login failure, reset password to prevent more attempts
|
// Login failure, reset password to prevent more attempts
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ class SnappyMailHelper
|
||||||
*/
|
*/
|
||||||
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
||||||
$oActions->Logger()->AddSecret($aCredentials[2]);
|
$oActions->Logger()->AddSecret($aCredentials[2]);
|
||||||
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false);
|
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2]);
|
||||||
if ($oAccount) {
|
if ($oAccount) {
|
||||||
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
||||||
$oActions->SetAuthToken($oAccount);
|
$oActions->SetAuthToken($oAccount);
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$iErrorCode = \RainLoop\Notifications::UnknownError;
|
$iErrorCode = \RainLoop\Notifications::UnknownError;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oAccount = $oActions->LoginProcess($sEmail, $sPassword, '', '', false, true);
|
$oAccount = $oActions->LoginProcess($sEmail, $sPassword);
|
||||||
if ($oAccount instanceof \RainLoop\Model\Account) {
|
if ($oAccount instanceof \RainLoop\Model\Account) {
|
||||||
$oActions->AuthToken($oAccount);
|
$oActions->AuthToken($oAccount);
|
||||||
$iErrorCode = 0;
|
$iErrorCode = 0;
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ trait Accounts
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bNew || $sPassword) {
|
if ($bNew || $sPassword) {
|
||||||
$oNewAccount = $this->LoginProcess($sEmail, $sPassword, false, false);
|
$oNewAccount = $this->LoginProcess($sEmail, $sPassword, false);
|
||||||
$aAccounts[$sEmail] = $oNewAccount->asTokenArray($oMainAccount);
|
$aAccounts[$sEmail] = $oNewAccount->asTokenArray($oMainAccount);
|
||||||
} else {
|
} else {
|
||||||
$aAccounts[$sEmail] = \RainLoop\Model\AdditionalAccount::convertArray($aAccounts[$sEmail]);
|
$aAccounts[$sEmail] = \RainLoop\Model\AdditionalAccount::convertArray($aAccounts[$sEmail]);
|
||||||
|
|
|
||||||
|
|
@ -36,18 +36,18 @@ trait User
|
||||||
{
|
{
|
||||||
$sEmail = \MailSo\Base\Utils::Trim($this->GetActionParam('Email', ''));
|
$sEmail = \MailSo\Base\Utils::Trim($this->GetActionParam('Email', ''));
|
||||||
$sPassword = $this->GetActionParam('Password', '');
|
$sPassword = $this->GetActionParam('Password', '');
|
||||||
$bSignMe = !empty($this->GetActionParam('signMe', 0));
|
|
||||||
|
|
||||||
$this->logMask($sPassword);
|
$this->logMask($sPassword);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$oAccount = $this->LoginProcess($sEmail, $sPassword, $bSignMe);
|
$oAccount = $this->LoginProcess($sEmail, $sPassword);
|
||||||
} catch (\Throwable $oException) {
|
} catch (\Throwable $oException) {
|
||||||
$this->loginErrorDelay();
|
$this->loginErrorDelay();
|
||||||
throw $oException;
|
throw $oException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->SetAuthToken($oAccount);
|
$this->SetAuthToken($oAccount);
|
||||||
|
empty($this->GetActionParam('signMe', 0)) || $this->SetSignMeToken($oAccount);
|
||||||
|
|
||||||
$this->Plugins()->RunHook('login.success', array($oAccount));
|
$this->Plugins()->RunHook('login.success', array($oAccount));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ trait UserAuth
|
||||||
/**
|
/**
|
||||||
* @throws \RainLoop\Exceptions\ClientException
|
* @throws \RainLoop\Exceptions\ClientException
|
||||||
*/
|
*/
|
||||||
public function LoginProcess(string &$sEmail, string &$sPassword, bool $bSignMe = false, bool $bMainAccount = true): Account
|
public function LoginProcess(string &$sEmail, string &$sPassword, bool $bMainAccount = true): Account
|
||||||
{
|
{
|
||||||
$sInputEmail = $sEmail;
|
$sInputEmail = $sEmail;
|
||||||
|
|
||||||
|
|
@ -139,14 +139,6 @@ trait UserAuth
|
||||||
|
|
||||||
$this->imapConnect($oAccount, true);
|
$this->imapConnect($oAccount, true);
|
||||||
if ($bMainAccount) {
|
if ($bMainAccount) {
|
||||||
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');
|
$this->StorageProvider()->Put($oAccount, StorageType::SESSION, Utils::GetSessionToken(), 'true');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,8 +326,14 @@ trait UserAuth
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function SetSignMeToken(MainAccount $oAccount): void
|
public function SetSignMeToken(MainAccount $oAccount): void
|
||||||
{
|
{
|
||||||
|
// SetAuthToken token needs to be called first
|
||||||
|
// because $_COOKIE['smctoken'] is used by Crypt::Passphrase.
|
||||||
|
// If the $_COOKIE['smctoken'] is not set then SetSignMeToken
|
||||||
|
// throws an exception
|
||||||
|
// $this->SetAuthToken($oAccount);
|
||||||
|
|
||||||
$this->ClearSignMeData();
|
$this->ClearSignMeData();
|
||||||
$uuid = \SnappyMail\UUID::generate();
|
$uuid = \SnappyMail\UUID::generate();
|
||||||
$data = \SnappyMail\Crypt::Encrypt($oAccount);
|
$data = \SnappyMail\Crypt::Encrypt($oAccount);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue