mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Move ServiceExternalLogin to plugin/extension
This commit is contained in:
parent
135c8f2c24
commit
9745d0ed89
5 changed files with 88 additions and 52 deletions
|
|
@ -273,7 +273,6 @@ curl_proxy_auth = ""
|
||||||
force_https = Off
|
force_https = Off
|
||||||
custom_login_link = ""
|
custom_login_link = ""
|
||||||
custom_logout_link = ""
|
custom_logout_link = ""
|
||||||
allow_external_login = Off
|
|
||||||
http_client_ip_check_proxy = Off
|
http_client_ip_check_proxy = Off
|
||||||
fast_cache_memcache_host = "127.0.0.1"
|
fast_cache_memcache_host = "127.0.0.1"
|
||||||
fast_cache_memcache_port = 11211
|
fast_cache_memcache_port = 11211
|
||||||
|
|
|
||||||
20
plugins/login-external/LICENSE
Normal file
20
plugins/login-external/LICENSE
Normal 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.
|
||||||
68
plugins/login-external/index.php
Normal file
68
plugins/login-external/index.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -402,7 +402,6 @@ Enables caching in the system'),
|
||||||
'force_https' => array(false),
|
'force_https' => array(false),
|
||||||
'custom_login_link' => array(''),
|
'custom_login_link' => array(''),
|
||||||
'custom_logout_link' => array(''),
|
'custom_logout_link' => array(''),
|
||||||
'allow_external_login' => array(false),
|
|
||||||
'allow_external_sso' => array(false),
|
'allow_external_sso' => array(false),
|
||||||
'external_sso_key' => array(''),
|
'external_sso_key' => array(''),
|
||||||
'http_client_ip_check_proxy' => array(false),
|
'http_client_ip_check_proxy' => array(false),
|
||||||
|
|
|
||||||
|
|
@ -761,56 +761,6 @@ class ServiceActions
|
||||||
return '';
|
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
|
public function ServiceExternalSso() : string
|
||||||
{
|
{
|
||||||
$this->oHttp->ServerNoCache();
|
$this->oHttp->ServerNoCache();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue