mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-01 21:49:21 +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
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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue