Closed dfangys closed 6 days ago
Checked, i don't see error.
the response is empty while it working in the old version
working after change it like this in /plugins/login-external
<?php
use SnappyMail\SensitiveString;
class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Login External',
AUTHOR = 'SnappyMail',
URL = 'https://snappymail.eu/',
VERSION = '1.3',
RELEASE = '2024-03-27',
REQUIRED = '2.36.1',
CATEGORY = 'Login',
LICENSE = 'MIT',
DESCRIPTION = 'Login with $_POST["Email"] and $_POST["Password"] from anywhere';
public function Init() : void
{
$this->addPartHook('ExternalLogin', 'ServiceExternalLogin');
}
public function ServiceExternalLogin() : bool
{
$oActions = \RainLoop\Api::Actions();
$oActions->Http()->ServerNoCache();
$oAccount = null;
$oException = null;
$sEmail = isset($_POST['Email']) ? $_POST['Email'] : '';
$sPassword = isset($_POST['Password']) ? $_POST['Password'] : '';
// Log received email and password
error_log("Received Email: $sEmail");
error_log("Received Password: $sPassword");
try
{
// Convert password to SensitiveString type
$oPassword = new SensitiveString($sPassword);
$oAccount = $oActions->LoginProcess($sEmail, $oPassword);
error_log("LoginProcess executed.");
if (!$oAccount instanceof \RainLoop\Model\MainAccount) {
$oAccount = null;
error_log("LoginProcess did not return a valid MainAccount.");
} else {
error_log("LoginProcess returned a valid MainAccount.");
}
}
catch (\Throwable $oException)
{
$oLogger = $oActions->Logger();
$oLogger && $oLogger->WriteException($oException);
// Log exception
error_log("Exception: " . $oException->getMessage());
}
if (isset($_POST['Output']) && 'json' === \strtolower($_POST['Output'])) {
\header('Content-Type: application/json; charset=utf-8');
$aResult = array(
'Action' => 'ExternalLogin',
'Result' => $oAccount ? true : false,
'ErrorCode' => 0
);
if (!$oAccount) {
if ($oException instanceof \RainLoop\Exceptions\ClientException) {
$aResult['ErrorCode'] = $oException->getCode();
} else {
// Set a default error code
$aResult['ErrorCode'] = 1; // Example error code
}
}
// Log JSON response
error_log("JSON Response: " . json_encode($aResult));
echo \json_encode($aResult);
} else {
\MailSo\Base\Http::Location('./');
}
return true;
}
}
?>
Thanks for finding the bug. Extension is updated.
Hello,
there's an issue with updates from 2.36.0 for external login, please check it.
domain.com/?ExternalLogin
thanks
Debug/logging information Read here how to log