mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-08 22:24:14 +08:00
Improved login handling for Nextcloud #96
This commit is contained in:
parent
00b08260e9
commit
c5d1e5e9c6
4 changed files with 25 additions and 7 deletions
|
@ -65,11 +65,11 @@ class FetchController extends Controller {
|
|||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sPostEmail);
|
||||
|
||||
$sPass = $_POST['snappymail-password'];
|
||||
if ('******' !== $sPass && '' !== $sPass) {
|
||||
if ('******' !== $sPass) {
|
||||
require_once $this->appManager->getAppPath('snappymail').'/lib/Util/SnappyMailHelper.php';
|
||||
|
||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-password',
|
||||
SnappyMailHelper::encodePassword($sPass, \md5($sPostEmail)));
|
||||
$sPass ? SnappyMailHelper::encodePassword($sPass, \md5($sPostEmail)) : '');
|
||||
}
|
||||
|
||||
$sEmail = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-email', '');
|
||||
|
|
|
@ -45,8 +45,8 @@ class Provider implements IProvider
|
|||
$result = [];
|
||||
SnappyMailHelper::startApp();
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oAccount = $oActions->getMainAccountFromToken(false);
|
||||
// $oAccount = $oActions->getAccountFromToken(false);
|
||||
// $oAccount = $oActions->getMainAccountFromToken(false); // Issue: when account switched, wrong email is shown
|
||||
$oAccount = $oActions->getAccountFromToken(false);
|
||||
$iCursor = (int) $query->getCursor();
|
||||
$iLimit = $query->getLimit();
|
||||
if ($oAccount) {
|
||||
|
|
|
@ -61,9 +61,9 @@ class SnappyMailHelper
|
|||
|
||||
public static function getLoginCredentials() : array
|
||||
{
|
||||
$config = \OC::$server->getConfig();
|
||||
$sEmail = '';
|
||||
$sPassword = '';
|
||||
$config = \OC::$server->getConfig();
|
||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
// Only store the user's password in the current session if they have
|
||||
// enabled auto-login using Nextcloud username or email address.
|
||||
|
@ -76,8 +76,9 @@ class SnappyMailHelper
|
|||
}
|
||||
// If the user has set credentials for SnappyMail in their personal
|
||||
// settings, override everything before and use those instead.
|
||||
$sEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', '');
|
||||
if ($sEmail) {
|
||||
$sCustomEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', '');
|
||||
if ($sCustomEmail) {
|
||||
$sEmail = $sCustomEmail;
|
||||
$sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', '');
|
||||
}
|
||||
return [$sEmail, $sPassword ? SnappyMailHelper::decodePassword($sPassword, \md5($sEmail)) : ''];
|
||||
|
|
|
@ -143,6 +143,23 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
'WebDAV' => $sWebDAV
|
||||
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
||||
];
|
||||
if (empty($aResult['Auth'])) {
|
||||
$config = \OC::$server->getConfig();
|
||||
// Only store the user's password in the current session if they have
|
||||
// enabled auto-login using Nextcloud username or email address.
|
||||
if ($config->getAppValue('snappymail', 'snappymail-autologin', false)) {
|
||||
$sEmail = $sUID;
|
||||
} else if ($config->getAppValue('snappymail', 'snappymail-autologin-with-email', false)) {
|
||||
$sEmail = $config->getUserValue($sUID, 'settings', 'email', '');
|
||||
}
|
||||
// If the user has set credentials for SnappyMail in their personal
|
||||
// settings, override everything before and use those instead.
|
||||
$sCustomEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', '');
|
||||
if ($sCustomEmail) {
|
||||
$sEmail = $sCustomEmail;
|
||||
}
|
||||
$aResult['DevEmail'] = $sEmail ?: '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue