Move ServiceExternalLogin to plugin/extension

This commit is contained in:
the-djmaze 2022-11-11 16:33:31 +01:00
parent 135c8f2c24
commit 9745d0ed89
5 changed files with 88 additions and 52 deletions

View file

@ -273,7 +273,6 @@ curl_proxy_auth = ""
force_https = Off
custom_login_link = ""
custom_logout_link = ""
allow_external_login = Off
http_client_ip_check_proxy = Off
fast_cache_memcache_host = "127.0.0.1"
fast_cache_memcache_port = 11211

View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2016 RainLoop Team
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -0,0 +1,68 @@
<?php
class LoginExternalPlugin extends \RainLoop\Plugins\AbstractPlugin
{
const
NAME = 'Login External',
AUTHOR = 'SnappyMail',
URL = 'https://snappymail.eu/',
VERSION = '1.0',
RELEASE = '2022-11-11',
REQUIRED = '2.21.0',
CATEGORY = 'Login',
LICENSE = 'MIT',
DESCRIPTION = '';
public function Init() : void
{
$this->addPartHook('ExternalLogin', 'ServiceExternalLogin');
}
public function ServiceExternalLogin() : bool
{
$oActions = \RainLoop\Api::Actions();
$oActions->Http()->ServerNoCache();
$oAccount = null;
$oException = null;
$sEmail = \trim($_POST['Email']);
$sPassword = $_POST['Password'];
try
{
$oAccount = $oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof \RainLoop\Model\MainAccount) {
$oActions->SetAuthToken($oAccount);
} else {
$oAccount = null;
}
}
catch (\Throwable $oException)
{
$oLogger = $oActions->Logger();
$oLogger && $oLogger->WriteException($oException);
}
if ('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 {
$aResult['ErrorCode'] = Notifications::AuthError;
}
}
echo Utils::jsonEncode($aResult);
} else {
$oActions->Location('./');
}
return true;
}
}

View file

@ -402,7 +402,6 @@ Enables caching in the system'),
'force_https' => array(false),
'custom_login_link' => array(''),
'custom_logout_link' => array(''),
'allow_external_login' => array(false),
'allow_external_sso' => array(false),
'external_sso_key' => array(''),
'http_client_ip_check_proxy' => array(false),

View file

@ -761,56 +761,6 @@ class ServiceActions
return '';
}
public function ServiceExternalLogin() : string
{
$this->oHttp->ServerNoCache();
$oException = null;
$oAccount = null;
if ($this->oActions->Config()->Get('labs', 'allow_external_login', false)) {
$sEmail = \trim($_POST['Email']);
$sPassword = $_POST['Password'];
try
{
$oAccount = $this->oActions->LoginProcess($sEmail, $sPassword);
if ($oAccount instanceof Model\MainAccount) {
$this->oActions->SetAuthToken($oAccount);
} else {
$oAccount = null;
}
}
catch (\Throwable $oException)
{
$this->Logger()->WriteException($oException);
}
}
if ('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 Exceptions\ClientException) {
$aResult['ErrorCode'] = $oException->getCode();
} else {
$aResult['ErrorCode'] = Notifications::AuthError;
}
}
return Utils::jsonEncode($aResult);
}
$this->oActions->Location('./');
return '';
}
public function ServiceExternalSso() : string
{
$this->oHttp->ServerNoCache();