mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Merge branch 'master' into addressbook
This commit is contained in:
commit
84c1fb5402
60 changed files with 574 additions and 629 deletions
107
plugins/change-password-froxlor/driver.php
Normal file
107
plugins/change-password-froxlor/driver.php
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
class ChangePasswordFroxlorDriver
|
||||
{
|
||||
const
|
||||
NAME = 'Froxlor',
|
||||
DESCRIPTION = 'Change passwords in Froxlor.';
|
||||
|
||||
/**
|
||||
* @var \RainLoop\Config\Plugin
|
||||
*/
|
||||
private $oConfig = null;
|
||||
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger = null;
|
||||
|
||||
function __construct(\RainLoop\Config\Plugin $oConfig, \MailSo\Log\Logger $oLogger)
|
||||
{
|
||||
$this->oConfig = $oConfig;
|
||||
$this->oLogger = $oLogger;
|
||||
}
|
||||
|
||||
public static function isSupported() : bool
|
||||
{
|
||||
return \class_exists('PDO', false)
|
||||
// The PHP extension PDO (mysql) must be installed to use this plugin
|
||||
&& \in_array('mysql', \PDO::getAvailableDrivers());
|
||||
}
|
||||
|
||||
public static function configMapping() : array
|
||||
{
|
||||
return array(
|
||||
\RainLoop\Plugins\Property::NewInstance('froxlor_dsn')->SetLabel('Froxlor PDO dsn')
|
||||
->SetDefaultValue('mysql:host=localhost;dbname=froxlor;charset=utf8'),
|
||||
\RainLoop\Plugins\Property::NewInstance('froxlor_user')->SetLabel('User'),
|
||||
\RainLoop\Plugins\Property::NewInstance('froxlor_password')->SetLabel('Password')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::PASSWORD),
|
||||
\RainLoop\Plugins\Property::NewInstance('froxlor_allowed_emails')->SetLabel('Allowed emails')
|
||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING_TEXT)
|
||||
->SetDescription('Allowed emails, space as delimiter, wildcard supported. Example: user1@domain1.net user2@domain1.net *@domain2.net')
|
||||
->SetDefaultValue('*')
|
||||
);
|
||||
}
|
||||
|
||||
public function ChangePassword(\RainLoop\Model\Account $oAccount, string $sPrevPassword, string $sNewPassword) : bool
|
||||
{
|
||||
if (!\RainLoop\Plugins\Helper::ValidateWildcardValues($oAccount->Email(), $this->oConfig->Get('plugin', 'froxlor_allowed_emails', ''))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ($this->oLogger) {
|
||||
$this->oLogger->Write('froxlor: Try to change password for '.$oAccount->Email());
|
||||
}
|
||||
|
||||
$oPdo = new \PDO(
|
||||
$this->oConfig->Get('plugin', 'froxlor_dsn', ''),
|
||||
$this->oConfig->Get('plugin', 'froxlor_user', ''),
|
||||
$this->oConfig->Get('plugin', 'froxlor_password', ''),
|
||||
array(
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
||||
)
|
||||
);
|
||||
|
||||
$oStmt = $oPdo->prepare('SELECT password_enc, id FROM mail_users WHERE username = ? LIMIT 1');
|
||||
|
||||
if ($oStmt->execute(array($oAccount->IncLogin()))) {
|
||||
$aFetchResult = $oStmt->fetch(\PDO::FETCH_ASSOC);
|
||||
if (!empty($aFetchResult['id'])) {
|
||||
$sDbPassword = $aFetchResult['password_enc'];
|
||||
$sDbSalt = \substr($sDbPassword, 0, \strrpos($sDbPassword, '$'));
|
||||
if (\crypt($sPrevPassword, $sDbSalt) === $sDbPassword) {
|
||||
|
||||
$oStmt = $oPdo->prepare('UPDATE mail_users SET password_enc = ? WHERE id = ?');
|
||||
|
||||
return !!$oStmt->execute(array(
|
||||
$this->cryptPassword($sNewPassword),
|
||||
$aFetchResult['id']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
if ($this->oLogger) {
|
||||
$this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function cryptPassword(string $sPassword) : string
|
||||
{
|
||||
if (\defined('CRYPT_SHA512') && CRYPT_SHA512) {
|
||||
$sSalt = '$6$rounds=5000$' . \bin2hex(\random_bytes(8)) . '$';
|
||||
} elseif (\defined('CRYPT_SHA256') && CRYPT_SHA256) {
|
||||
$sSalt = '$5$rounds=5000$' . \bin2hex(\random_bytes(8)) . '$';
|
||||
} else {
|
||||
$sSalt = '$1$' . \bin2hex(\random_bytes(6)) . '$';
|
||||
}
|
||||
return \crypt($sPassword, $sSalt);
|
||||
}
|
||||
}
|
||||
20
plugins/change-password-froxlor/index.php
Normal file
20
plugins/change-password-froxlor/index.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
use \RainLoop\Exceptions\ClientException;
|
||||
|
||||
class ChangePasswordPoppassdPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Change Password Froxlor',
|
||||
AUTHOR = 'Euphonique',
|
||||
VERSION = '1.0',
|
||||
RELEASE = '2022-05-30',
|
||||
REQUIRED = '2.15.3',
|
||||
CATEGORY = 'Security',
|
||||
DESCRIPTION = 'Extension to allow users to change their passwords through Froxlor';
|
||||
|
||||
public function Supported() : string
|
||||
{
|
||||
return 'Use Change Password plugin';
|
||||
}
|
||||
}
|
||||
|
|
@ -9,22 +9,21 @@ class ChangeSmtpEhloMessagePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('smtp.credentials', 'FilterSmtpCredentials');
|
||||
$this->addHook('smtp.before-connect', 'FilterSmtpCredentials');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param array $aSmtpCredentials
|
||||
*/
|
||||
public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
|
||||
public function FilterSmtpCredentials(\RainLoop\Model\Account $oAccount,
|
||||
\MailSo\Smtp\SmtpClient $oSmtpClient,
|
||||
array &$aSmtpCredentials)
|
||||
{
|
||||
if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
|
||||
{
|
||||
// Default:
|
||||
// $aSmtpCredentials['Ehlo'] = \MailSo\Smtp\SmtpClient::EhloHelper();
|
||||
//
|
||||
// or write your custom php
|
||||
$aSmtpCredentials['Ehlo'] = 'localhost';
|
||||
}
|
||||
// Default:
|
||||
// $aSmtpCredentials['Ehlo'] = \MailSo\Smtp\SmtpClient::EhloHelper();
|
||||
//
|
||||
// or write your custom php
|
||||
$aSmtpCredentials['Ehlo'] = 'localhost';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ContactsExampleSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
|
||||
{
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process(RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20): array
|
||||
{
|
||||
$aResult = array(
|
||||
array($oAccount->Email(), ''),
|
||||
array('email@domain.com', 'name')
|
||||
);
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 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.
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ContactsSuggestionsExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Custom Contacts Suggestions Example',
|
||||
CATEGORY = 'General',
|
||||
DESCRIPTION = 'Custom contacts suggestions example';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName
|
||||
* @param mixed $mResult
|
||||
*/
|
||||
public function MainFabrica($sName, &$mResult)
|
||||
{
|
||||
switch ($sName)
|
||||
{
|
||||
case 'suggestions':
|
||||
|
||||
if (!\is_array($mResult))
|
||||
{
|
||||
$mResult = array();
|
||||
}
|
||||
|
||||
include_once __DIR__.'/ContactsExampleSuggestions.php';
|
||||
$mResult[] = new ContactsExampleSuggestions();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
class CustomAdminSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Custom Admin Settings',
|
||||
CATEGORY = 'General',
|
||||
DESCRIPTION = 'Custom admin settings example';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function Init() : void
|
||||
{
|
||||
$this->UseLangs(true); // start use langs folder
|
||||
|
||||
$this->addJs('js/CustomAdminSettings.js', true); // add js file
|
||||
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
|
||||
|
||||
$this->addTemplate('templates/PluginCustomAdminSettingsTab.html', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonAdminGetData()
|
||||
{
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'PHP' => phpversion()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
|
||||
(function () {
|
||||
|
||||
if (!window.rl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function CustomAdminSettings()
|
||||
{
|
||||
this.php = ko.observable('');
|
||||
|
||||
this.loading = ko.observable(false);
|
||||
}
|
||||
|
||||
CustomAdminSettings.prototype.onBuild = function () // special function
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
self.loading(false);
|
||||
|
||||
if (!iError) {
|
||||
self.php(oData.Result.PHP || '');
|
||||
}
|
||||
|
||||
if (rl.Enums.StorageResultType.Abort === iError) {
|
||||
// show abort
|
||||
}
|
||||
|
||||
}, 'JsonAdminGetData');
|
||||
|
||||
};
|
||||
|
||||
rl.addSettingsViewModelForAdmin(CustomAdminSettings, 'PluginCustomAdminSettingsTab',
|
||||
'SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/TAB_NAME', 'custom');
|
||||
|
||||
}());
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN]
|
||||
TAB_NAME = "Custom Extension Tab"
|
||||
LEGEND_CUSTOM = "Custom Extension Tab (Example)"
|
||||
LABEL_PHP_VERSION = "PHP version"
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN]
|
||||
TAB_NAME = "Плагин"
|
||||
LEGEND_CUSTOM = "Плагин (Пример)"
|
||||
LABEL_PHP_VERSION = "PHP версия"
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 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.
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
<?php
|
||||
|
||||
class CustomAuthExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Custom Auth Example Extension',
|
||||
VERSION = '2.1',
|
||||
REQUIRED = '2.5.0',
|
||||
CATEGORY = 'Login',
|
||||
DESCRIPTION = 'Custom auth mechanism example';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
$this->addHook('login.credentials', 'FilterLoginCredentials');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sLogin
|
||||
* @param string $sPassword
|
||||
*
|
||||
* @throws \RainLoop\Exceptions\ClientException
|
||||
*/
|
||||
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
|
||||
{
|
||||
// Your custom php logic
|
||||
// You may change login credentials
|
||||
if ('demo@snappymail.eu' === $sEmail)
|
||||
{
|
||||
$sEmail = 'user@snappymail.eu';
|
||||
$sLogin = 'user@snappymail.eu';
|
||||
$sPassword = 'super-puper-password';
|
||||
}
|
||||
else
|
||||
{
|
||||
// or throw auth exeption
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 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.
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
class CustomSettingsTabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Custom Settings Tab',
|
||||
CATEGORY = 'General',
|
||||
DESCRIPTION = 'Example extension for custom settings tabs';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function Init() : void
|
||||
{
|
||||
$this->UseLangs(true); // start use langs folder
|
||||
|
||||
$this->addJs('js/CustomUserSettings.js'); // add js file
|
||||
|
||||
$this->addJsonHook('JsonGetCustomUserData', 'JsonGetCustomUserData');
|
||||
$this->addJsonHook('JsonSaveCustomUserData', 'JsonSaveCustomUserData');
|
||||
|
||||
$this->addTemplate('templates/PluginCustomSettingsTab.html');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonGetCustomUserData()
|
||||
{
|
||||
$aSettings = $this->getUserSettings();
|
||||
|
||||
$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
|
||||
$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
|
||||
|
||||
// or get user's data from your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonSaveCustomUserData()
|
||||
{
|
||||
$sUserFacebook = $this->jsonParam('UserFacebook');
|
||||
$sUserSkype = $this->jsonParam('UserSkype');
|
||||
|
||||
// or put user's data to your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
|
||||
(function () {
|
||||
|
||||
if (!window.rl)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
function CustomUserSettings()
|
||||
{
|
||||
this.userSkype = ko.observable('');
|
||||
this.userFacebook = ko.observable('');
|
||||
|
||||
this.loading = ko.observable(false);
|
||||
this.saving = ko.observable(false);
|
||||
|
||||
this.savingOrLoading = ko.computed(function () {
|
||||
return this.loading() || this.saving();
|
||||
}, this);
|
||||
}
|
||||
|
||||
CustomUserSettings.prototype.customJsonSaveData = function ()
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if (this.saving())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
this.saving(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
self.saving(false);
|
||||
|
||||
if (!iError)
|
||||
{
|
||||
// true
|
||||
}
|
||||
else if (rl.Enums.StorageResultType.Abort === iError) {
|
||||
// show abort
|
||||
}
|
||||
else
|
||||
{
|
||||
// false
|
||||
}
|
||||
|
||||
}, 'JsonSaveCustomUserData', {
|
||||
'UserSkype': this.userSkype(),
|
||||
'UserFacebook': this.userFacebook()
|
||||
});
|
||||
};
|
||||
|
||||
CustomUserSettings.prototype.onBuild = function () // special function
|
||||
{
|
||||
var self = this;
|
||||
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
self.loading(false);
|
||||
|
||||
if (!iError)
|
||||
{
|
||||
self.userSkype(oData.Result.UserSkype || '');
|
||||
self.userFacebook(oData.Result.UserFacebook || '');
|
||||
}
|
||||
|
||||
}, 'JsonGetCustomUserData');
|
||||
|
||||
};
|
||||
|
||||
rl.addSettingsViewModel(CustomUserSettings, 'PluginCustomSettingsTab',
|
||||
'SETTINGS_CUSTOM_PLUGIN/TAB_NAME', 'custom');
|
||||
|
||||
}());
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[SETTINGS_CUSTOM_PLUGIN]
|
||||
TAB_NAME = "Custom Extension"
|
||||
LEGEND_CUSTOM = "Custom Extension (Example)"
|
||||
LABEL_SKYPE = "Skype"
|
||||
LABEL_FACEBOOK = "Facebook"
|
||||
BUTTON_SAVE = "Save"
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[SETTINGS_CUSTOM_PLUGIN]
|
||||
TAB_NAME = "Плагин"
|
||||
LEGEND_CUSTOM = "Плагин (Пример)"
|
||||
LABEL_SKYPE = "Skype"
|
||||
LABEL_FACEBOOK = "Facebook"
|
||||
BUTTON_SAVE = "Сохранить"
|
||||
|
|
@ -31,6 +31,22 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
$this->addTemplate(string $sFile, bool $bAdminScope = false);
|
||||
$this->addTemplateHook(string $sName, string $sPlace, string $sLocalTemplateName, bool $bPrepend = false);
|
||||
*/
|
||||
|
||||
// $this->addHook('login.credentials', 'FilterLoginCredentials');
|
||||
|
||||
|
||||
$this->UseLangs(true); // start use langs folder
|
||||
|
||||
// User Settings tab
|
||||
$this->addJs('js/ExampleUserSettings.js'); // add js file
|
||||
$this->addJsonHook('JsonGetExampleUserData', 'JsonGetExampleUserData');
|
||||
$this->addJsonHook('JsonSaveExampleUserData', 'JsonSaveExampleUserData');
|
||||
$this->addTemplate('templates/ExampleUserSettingsTab.html');
|
||||
|
||||
// Admin Settings tab
|
||||
$this->addJs('js/ExampleAdminSettings.js', true); // add js file
|
||||
$this->addJsonHook('JsonAdminGetData', 'JsonAdminGetData');
|
||||
$this->addTemplate('templates/ExampleAdminSettingsTab.html', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +77,77 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
|
|||
}
|
||||
}
|
||||
|
||||
public function JsonAdminGetData()
|
||||
{
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'PHP' => \phpversion()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sEmail
|
||||
* @param string $sLogin
|
||||
* @param string $sPassword
|
||||
*
|
||||
* @throws \RainLoop\Exceptions\ClientException
|
||||
*/
|
||||
public function FilterLoginCredentials(&$sEmail, &$sLogin, &$sPassword)
|
||||
{
|
||||
// Your custom php logic
|
||||
// You may change login credentials
|
||||
if ('demo@snappymail.eu' === $sEmail)
|
||||
{
|
||||
$sEmail = 'user@snappymail.eu';
|
||||
$sLogin = 'user@snappymail.eu';
|
||||
$sPassword = 'super-duper-password';
|
||||
}
|
||||
else
|
||||
{
|
||||
// or throw auth exeption
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AuthError);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::AccountNotAllowed);
|
||||
// or
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::DomainNotAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonGetExampleUserData()
|
||||
{
|
||||
$aSettings = $this->getUserSettings();
|
||||
|
||||
$sUserFacebook = isset($aSettings['UserFacebook']) ? $aSettings['UserFacebook'] : '';
|
||||
$sUserSkype = isset($aSettings['UserSkype']) ? $aSettings['UserSkype'] : '';
|
||||
|
||||
// or get user's data from your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function JsonSaveExampleUserData()
|
||||
{
|
||||
$sUserFacebook = $this->jsonParam('UserFacebook');
|
||||
$sUserSkype = $this->jsonParam('UserSkype');
|
||||
|
||||
// or put user's data to your custom storage ( DB / LDAP / ... ).
|
||||
|
||||
\sleep(1);
|
||||
return $this->jsonResponse(__FUNCTION__, $this->saveUserSettings(array(
|
||||
'UserFacebook' => $sUserFacebook,
|
||||
'UserSkype' => $sUserSkype
|
||||
)));
|
||||
}
|
||||
|
||||
/*
|
||||
public function Config() : \RainLoop\Config\Plugin
|
||||
public function Description() : string
|
||||
|
|
|
|||
37
plugins/example/js/ExampleAdminSettings.js
Normal file
37
plugins/example/js/ExampleAdminSettings.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
(rl => { if (rl) {
|
||||
|
||||
class ExampleAdminSettings
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.php = ko.observable('');
|
||||
this.loading = ko.observable(false);
|
||||
}
|
||||
|
||||
onBuild()
|
||||
{
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.loading(false);
|
||||
|
||||
if (iError) {
|
||||
console.error({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
} else {
|
||||
this.php(oData.Result.PHP || '');
|
||||
}
|
||||
|
||||
}, 'JsonAdminGetData');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModelForAdmin(ExampleAdminSettings, 'ExampleAdminSettingsTab',
|
||||
'SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/TAB_NAME', 'Example');
|
||||
|
||||
}})(window.rl);
|
||||
68
plugins/example/js/ExampleUserSettings.js
Normal file
68
plugins/example/js/ExampleUserSettings.js
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
(rl => { if (rl) {
|
||||
|
||||
class ExampleUserSettings
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
this.userSkype = ko.observable('');
|
||||
this.userFacebook = ko.observable('');
|
||||
|
||||
this.loading = ko.observable(false);
|
||||
this.saving = ko.observable(false);
|
||||
|
||||
this.savingOrLoading = ko.computed(() => {
|
||||
return this.loading() || this.saving();
|
||||
});
|
||||
}
|
||||
|
||||
exampleJsonSaveData()
|
||||
{
|
||||
if (!this.saving()) {
|
||||
this.saving(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.saving(false);
|
||||
|
||||
if (iError) {
|
||||
console.error({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
} else {
|
||||
console.dir({
|
||||
iError: iError,
|
||||
oData: oData
|
||||
});
|
||||
}
|
||||
|
||||
}, 'JsonSaveExampleUserData', {
|
||||
'UserSkype': this.userSkype(),
|
||||
'UserFacebook': this.userFacebook()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onBuild()
|
||||
{
|
||||
this.loading(true);
|
||||
|
||||
rl.pluginRemoteRequest((iError, oData) => {
|
||||
|
||||
this.loading(false);
|
||||
|
||||
if (!iError) {
|
||||
self.userSkype(oData.Result.UserSkype || '');
|
||||
self.userFacebook(oData.Result.UserFacebook || '');
|
||||
}
|
||||
|
||||
}, 'JsonGetExampleUserData');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModel(ExampleUserSettings, 'ExampleUserSettingsTab',
|
||||
'SETTINGS_EXAMPLE_PLUGIN/TAB_NAME', 'Example');
|
||||
|
||||
}})(window.rl);
|
||||
15
plugins/example/langs/en.json
Normal file
15
plugins/example/langs/en.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN": {
|
||||
"TAB_NAME": "Example Extension Tab",
|
||||
"LEGEND_EXAMPLE": "Example Extension Tab (Example)",
|
||||
"LABEL_PHP_VERSION": "PHP version"
|
||||
},
|
||||
"SETTINGS_EXAMPLE_PLUGIN": {
|
||||
"TAB_NAME": "Example Extension",
|
||||
"LEGEND_EXAMPLE": "Example Extension (Example)",
|
||||
"LABEL_PHP_VERSION": "PHP version",
|
||||
"LABEL_SKYPE": "Skype",
|
||||
"LABEL_FACEBOOK": "Facebook",
|
||||
"BUTTON_SAVE": "Save"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
<div>
|
||||
<div class="form-horizontal">
|
||||
<div class="legend">
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/LEGEND_CUSTOM"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LEGEND_EXAMPLE"></span>
|
||||
|
||||
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_ADMIN_CUSTOM_TAB_PLUGIN/LABEL_PHP_VERSION"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_ADMIN_EXAMPLE_TAB_PLUGIN/LABEL_PHP_VERSION"></span>
|
||||
</label>
|
||||
<div class="controls" style="padding-top: 5px">
|
||||
<b data-bind="text: php"></b>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
<div>
|
||||
<div class="form-horizontal">
|
||||
<div class="legend">
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LEGEND_CUSTOM"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LEGEND_EXAMPLE"></span>
|
||||
|
||||
<i class="icon-spinner animated" style="margin-top: 5px" data-bind="visible: loading"></i>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LABEL_SKYPE"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_SKYPE"></span>
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" data-bind="value: userSkype, enable: !savingOrLoading()" />
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/LABEL_FACEBOOK"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/LABEL_FACEBOOK"></span>
|
||||
</label>
|
||||
<div class="controls">
|
||||
<input type="text" data-bind="value: userFacebook, enable: !savingOrLoading()" />
|
||||
|
|
@ -23,10 +23,10 @@
|
|||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<button class="btn" data-bind="click: customJsonSaveData, enable: !savingOrLoading()">
|
||||
<button class="btn" data-bind="click: exampleJsonSaveData, enable: !savingOrLoading()">
|
||||
<i data-bind="css: {'icon-floppy': !saving(), 'icon-spinner animated': saving()}" class="icon-floppy"></i>
|
||||
|
||||
<span class="i18n" data-i18n="SETTINGS_CUSTOM_PLUGIN/BUTTON_SAVE"></span>
|
||||
<span class="i18n" data-i18n="SETTINGS_EXAMPLE_PLUGIN/BUTTON_SAVE"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue