mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-13 16:44:37 +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);
|
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-email', $sPostEmail);
|
||||||
|
|
||||||
$sPass = $_POST['snappymail-password'];
|
$sPass = $_POST['snappymail-password'];
|
||||||
if ('******' !== $sPass && '' !== $sPass) {
|
if ('******' !== $sPass) {
|
||||||
require_once $this->appManager->getAppPath('snappymail').'/lib/Util/SnappyMailHelper.php';
|
require_once $this->appManager->getAppPath('snappymail').'/lib/Util/SnappyMailHelper.php';
|
||||||
|
|
||||||
$this->config->setUserValue($sUser, 'snappymail', 'snappymail-password',
|
$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', '');
|
$sEmail = $this->config->getUserValue($sUser, 'snappymail', 'snappymail-email', '');
|
||||||
|
|
|
@ -45,8 +45,8 @@ class Provider implements IProvider
|
||||||
$result = [];
|
$result = [];
|
||||||
SnappyMailHelper::startApp();
|
SnappyMailHelper::startApp();
|
||||||
$oActions = \RainLoop\Api::Actions();
|
$oActions = \RainLoop\Api::Actions();
|
||||||
$oAccount = $oActions->getMainAccountFromToken(false);
|
// $oAccount = $oActions->getMainAccountFromToken(false); // Issue: when account switched, wrong email is shown
|
||||||
// $oAccount = $oActions->getAccountFromToken(false);
|
$oAccount = $oActions->getAccountFromToken(false);
|
||||||
$iCursor = (int) $query->getCursor();
|
$iCursor = (int) $query->getCursor();
|
||||||
$iLimit = $query->getLimit();
|
$iLimit = $query->getLimit();
|
||||||
if ($oAccount) {
|
if ($oAccount) {
|
||||||
|
|
|
@ -61,9 +61,9 @@ class SnappyMailHelper
|
||||||
|
|
||||||
public static function getLoginCredentials() : array
|
public static function getLoginCredentials() : array
|
||||||
{
|
{
|
||||||
$config = \OC::$server->getConfig();
|
|
||||||
$sEmail = '';
|
$sEmail = '';
|
||||||
$sPassword = '';
|
$sPassword = '';
|
||||||
|
$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
|
// 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.
|
||||||
|
@ -76,8 +76,9 @@ class SnappyMailHelper
|
||||||
}
|
}
|
||||||
// If the user has set credentials for SnappyMail in their personal
|
// If the user has set credentials for SnappyMail in their personal
|
||||||
// settings, override everything before and use those instead.
|
// settings, override everything before and use those instead.
|
||||||
$sEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', '');
|
$sCustomEmail = $config->getUserValue($sUID, 'snappymail', 'snappymail-email', '');
|
||||||
if ($sEmail) {
|
if ($sCustomEmail) {
|
||||||
|
$sEmail = $sCustomEmail;
|
||||||
$sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', '');
|
$sPassword = $config->getUserValue($sUID, 'snappymail', 'snappymail-password', '');
|
||||||
}
|
}
|
||||||
return [$sEmail, $sPassword ? SnappyMailHelper::decodePassword($sPassword, \md5($sEmail)) : ''];
|
return [$sEmail, $sPassword ? SnappyMailHelper::decodePassword($sPassword, \md5($sEmail)) : ''];
|
||||||
|
|
|
@ -143,6 +143,23 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
'WebDAV' => $sWebDAV
|
'WebDAV' => $sWebDAV
|
||||||
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
// '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