mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-09 06:34:28 +08:00
Resolve #561
This commit is contained in:
parent
e3ffad8552
commit
c199b63304
2 changed files with 41 additions and 29 deletions
|
@ -84,17 +84,13 @@ class Application extends App implements IBootstrap
|
||||||
// $userSession->listen('\OC\User', 'postRememberedLogin', function($loginName, $password) {
|
// $userSession->listen('\OC\User', 'postRememberedLogin', function($loginName, $password) {
|
||||||
$userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) {
|
$userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
$sEmail = '';
|
|
||||||
// Only store the user's password in the current session if they have
|
// Only store the user's password in the current session if they have
|
||||||
// enabled auto-login using Nextcloud username or email address.
|
// enabled auto-login using Nextcloud username or email address.
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)) {
|
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)
|
||||||
$sEmail = $user->getUID();
|
|| $config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||||
} else if ($config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
$sUID = $user->getUID();
|
||||||
$sEmail = $config->getUserValue($user->getUID(), 'settings', 'email', '');
|
\OC::$server->getSession()['snappymail-nc-uid'] = $sUID;
|
||||||
}
|
\OC::$server->getSession()['snappymail-password'] = SnappyMailHelper::encodePassword($password, $sUID);
|
||||||
if ($sEmail) {
|
|
||||||
\OC::$server->getSession()['snappymail-email'] = $sEmail;
|
|
||||||
\OC::$server->getSession()['snappymail-password'] = SnappyMailHelper::encodePassword($password, \md5($sEmail));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,14 @@ class SnappyMailHelper
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true;
|
$_ENV['SNAPPYMAIL_NEXTCLOUD'] = true; // Obsolete
|
||||||
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
$_ENV['SNAPPYMAIL_INCLUDE_AS_API'] = true;
|
||||||
|
|
||||||
|
// define('APP_VERSION', '0.0.0');
|
||||||
|
// define('APP_INDEX_ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
|
||||||
|
// include APP_INDEX_ROOT_PATH.'snappymail/v/'.APP_VERSION.'/include.php';
|
||||||
|
// define('APP_DATA_FOLDER_PATH', \rtrim(\trim(\OC::$server->getSystemConfig()->getValue('datadirectory', '')), '\\/').'/appdata_snappymail/');
|
||||||
|
|
||||||
require_once \dirname(\dirname(__DIR__)) . '/app/index.php';
|
require_once \dirname(\dirname(__DIR__)) . '/app/index.php';
|
||||||
|
|
||||||
$oConfig = \RainLoop\Api::Config();
|
$oConfig = \RainLoop\Api::Config();
|
||||||
|
@ -96,15 +101,20 @@ class SnappyMailHelper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$aCredentials = SnappyMailHelper::getLoginCredentials();
|
$aCredentials = static::getLoginCredentials();
|
||||||
if ($oActions->getMainAccountFromToken(false)) {
|
$ocSession = \OC::$server->getSession();
|
||||||
if (!$aCredentials[0] || !$aCredentials[1]) {
|
$doLogin = !$oActions->getMainAccountFromToken(false);
|
||||||
$oActions->Logout(true);
|
if (!$doLogin && $ocSession['snappymail-uid'] && $ocSession['snappymail-uid'] != $aCredentials[0]) {
|
||||||
}
|
// UID changed, Impersonate plugin probably active
|
||||||
} else if ($aCredentials[0] && $aCredentials[1]) {
|
$ocSession['snappymail-uid'] = false;
|
||||||
$oActions->Logger()->AddSecret($aCredentials[1]);
|
$oActions->Logout(true);
|
||||||
$oAccount = $oActions->LoginProcess($aCredentials[0], $aCredentials[1], false);
|
$doLogin = true;
|
||||||
|
}
|
||||||
|
if ($doLogin && $aCredentials[1] && $aCredentials[2]) {
|
||||||
|
$oActions->Logger()->AddSecret($aCredentials[2]);
|
||||||
|
$oAccount = $oActions->LoginProcess($aCredentials[1], $aCredentials[2], false);
|
||||||
if ($oAccount) {
|
if ($oAccount) {
|
||||||
|
$ocSession['snappymail-uid'] = $aCredentials[0];
|
||||||
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
$oActions->Plugins()->RunHook('login.success', array($oAccount));
|
||||||
$oActions->SetAuthToken($oAccount);
|
$oActions->SetAuthToken($oAccount);
|
||||||
}
|
}
|
||||||
|
@ -127,17 +137,20 @@ class SnappyMailHelper
|
||||||
$sPassword = '';
|
$sPassword = '';
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
// Only store the user's password in the current session if they have
|
$ocSession = \OC::$server->getSession();
|
||||||
|
// Only use the user's password in the current session if they have
|
||||||
// enabled auto-login using Nextcloud username or email address.
|
// enabled auto-login using Nextcloud username or email address.
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)) {
|
if ($ocSession['snappymail-nc-uid'] == $sUID) {
|
||||||
$sEmail = $sUID;
|
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)) {
|
||||||
$sPassword = \OC::$server->getSession()['snappymail-password'];
|
$sEmail = $sUID;
|
||||||
} else if ($config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
$sPassword = $ocSession['snappymail-password'];
|
||||||
$sEmail = $config->getUserValue($sUID, 'settings', 'email', '');
|
} else if ($config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||||
$sPassword = \OC::$server->getSession()['snappymail-password'];
|
$sEmail = $config->getUserValue($sUID, 'settings', 'email', '');
|
||||||
}
|
$sPassword = $ocSession['snappymail-password'];
|
||||||
if (\OC::$server->getSession()['snappymail-email'] != $sEmail) {
|
}
|
||||||
$sPassword = '';
|
if ($sPassword) {
|
||||||
|
$sPassword = static::decodePassword($sPassword, $sUID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user has set credentials for SnappyMail in their personal
|
// If the user has set credentials for SnappyMail in their personal
|
||||||
|
@ -146,8 +159,11 @@ class SnappyMailHelper
|
||||||
if ($sCustomEmail) {
|
if ($sCustomEmail) {
|
||||||
$sEmail = $sCustomEmail;
|
$sEmail = $sCustomEmail;
|
||||||
$sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', '');
|
$sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', '');
|
||||||
|
if ($sPassword) {
|
||||||
|
$sPassword = static::decodePassword($sPassword, \md5($sEmail));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return [$sEmail, $sPassword ? SnappyMailHelper::decodePassword($sPassword, \md5($sEmail)) : ''];
|
return [$sUID, $sEmail, $sPassword ?: ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAppUrl() : string
|
public static function getAppUrl() : string
|
||||||
|
|
Loading…
Add table
Reference in a new issue