Some small formatting changes for ldap identities
FWest98 accidentally removed `case 'suggestions': $mResult = [];` in fabrica?
This commit is contained in:
djmaze 2020-11-13 09:56:40 +01:00
parent fb680596a6
commit 1670ca0db1
7 changed files with 46 additions and 41 deletions

View file

@ -132,7 +132,7 @@ class LdapIdentities implements IIdentities
* @inheritDoc
* @throws \RainLoop\Exceptions\Exception
*/
public function SetIdentities(Account $account, array $identities)
public function SetIdentities(Account $account, array $identities): void
{
throw new \RainLoop\Exceptions\Exception("Ldap identities provider does not support storage");
}
@ -307,4 +307,4 @@ class LdapResult
/** @var string[] */
public $emails;
}
}

View file

@ -279,7 +279,11 @@ class Actions
$mResult = new Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
}
break;
case 'identities':
$mResult = [];
break;
case 'suggestions':
$mResult = [];
break;
case 'two-factor-auth':
// Providers\TwoFactorAuth\TwoFactorAuthInterface
@ -289,8 +293,7 @@ class Actions
}
// Always give the file provider as last for identities, it is the override
if ($sName === 'identities') {
if ($mResult === null) $mResult = [];
if ('identities' === $sName) {
$mResult[] = new Providers\Identities\FileIdentities($this->StorageProvider(true));
}
@ -921,8 +924,8 @@ class Actions
empty($aAccountHash[5]) ? '' : $aAccountHash[5], empty($aAccountHash[11]) ? '' : $aAccountHash[11], $bThrowExceptionOnFalse);
if ($oAccount) {
if (!empty($aAccountHash[8]) && !empty($aAccountHash[9])) // init proxy user/password
{
// init proxy user/password
if (!empty($aAccountHash[8]) && !empty($aAccountHash[9])) {
$oAccount->SetProxyAuthUser($aAccountHash[8]);
$oAccount->SetProxyAuthPassword($aAccountHash[9]);
}
@ -1075,15 +1078,15 @@ class Actions
'Plugins' => array(),
'System' => $this->AppDataSystem($bAdmin, $bMobile, $bMobileDevice)
/*
'LoginLogo' => $oConfig->Get('branding', 'login_logo', ''),
'LoginBackground' => $oConfig->Get('branding', 'login_background', ''),
'LoginCss' => $oConfig->Get('branding', 'login_css', ''),
'LoginDescription' => $oConfig->Get('branding', 'login_desc', ''),
'UserLogo' => $oConfig->Get('branding', 'user_logo', ''),
'UserLogoTitle' => $oConfig->Get('branding', 'user_logo_title', ''),
'UserLogoMessage' => $oConfig->Get('branding', 'user_logo_message', ''),
'UserIframeMessage' => $oConfig->Get('branding', 'user_iframe_message', ''),
'UserCss' => $oConfig->Get('branding', 'user_css', ''),
'LoginLogo' => $oConfig->Get('branding', 'login_logo', ''),
'LoginBackground' => $oConfig->Get('branding', 'login_background', ''),
'LoginCss' => $oConfig->Get('branding', 'login_css', ''),
'LoginDescription' => $oConfig->Get('branding', 'login_desc', ''),
'UserLogo' => $oConfig->Get('branding', 'user_logo', ''),
'UserLogoTitle' => $oConfig->Get('branding', 'user_logo_title', ''),
'UserLogoMessage' => $oConfig->Get('branding', 'user_logo_message', ''),
'UserIframeMessage' => $oConfig->Get('branding', 'user_iframe_message', ''),
'UserCss' => $oConfig->Get('branding', 'user_css', ''),
*/
);

View file

@ -175,8 +175,6 @@ trait Accounts
*/
public function GetIdentities(Account $account): array
{
if (!$account) return [];
// A custom name for a single identity is also stored in this system
$allowMultipleIdentities = $this->GetCapa(false, false, Capa::IDENTITIES, $account);
@ -185,15 +183,17 @@ trait Accounts
// Sort identities
$orderString = $this->StorageProvider()->Get($account, StorageType::CONFIG, 'accounts_identities_order');
$order = json_decode($orderString, true) ?? [];
if (isset($order['Identities']) && is_array($order['Identities']) && count($order['Identities']) > 1) {
$list = array_map(function ($item) {
if ('' === $item) $item = '---';
$order = \json_decode($orderString, true) ?? [];
if (isset($order['Identities']) && \is_array($order['Identities']) && \count($order['Identities']) > 1) {
$list = \array_map(function ($item) {
if ('' === $item) {
$item = '---';
}
return $item;
}, $order['Identities']);
usort($identities, function ($a, $b) use ($list) {
return array_search($a->Id(true), $list) < array_search($b->Id(true), $list) ? -1 : 1;
\usort($identities, function ($a, $b) use ($list) {
return \array_search($a->Id(true), $list) < \array_search($b->Id(true), $list) ? -1 : 1;
});
}

View file

@ -22,7 +22,7 @@ class Identities extends AbstractProvider
{
if ($drivers === null) $drivers = [];
$this->drivers = array_filter($drivers, function ($driver) {
$this->drivers = \array_filter($drivers, function ($driver) {
return $driver instanceof IIdentities;
});
}
@ -38,7 +38,7 @@ class Identities extends AbstractProvider
$identities = $this->MergeIdentitiesPerDriver($this->GetIdentiesPerDriver($account));
// Find the primary identity
$primaryIdentity = current(array_filter($identities, function ($identity) {
$primaryIdentity = \current(\array_filter($identities, function ($identity) {
return $identity->IsAccountIdentities();
}));
@ -73,7 +73,7 @@ class Identities extends AbstractProvider
// If it is a new identity we add it to any storage driver
if ($isNew) {
// Pick any storage driver to store the result, typically only file storage
$storageDriver = current(array_filter($this->drivers, function ($driver) {
$storageDriver = \current(\array_filter($this->drivers, function ($driver) {
return $driver->SupportsStore();
}));
@ -134,6 +134,6 @@ class Identities extends AbstractProvider
$identities[$identity->Id(true)] = $identity;
}
return array_values($identities);
return \array_values($identities);
}
}
}

View file

@ -27,18 +27,20 @@ class FileIdentities implements IIdentities
*/
public function GetIdentities(Account $account): array
{
if (!$account) return [];
$data = $this->localStorageProvider->Get($account, Storage\Enumerations\StorageType::CONFIG, 'identities');
$subIdentities = json_decode($data, true) ?? [];
$subIdentities = \json_decode($data, true) ?? [];
$result = [];
foreach ($subIdentities as $subIdentity) {
$identity = new Identity();
$identity->FromJSON($subIdentity);
if (!$identity->Validate()) continue;
if ($identity->IsAccountIdentities()) $identity->SetEmail($account->Email());
if (!$identity->Validate()) {
continue;
}
if ($identity->IsAccountIdentities()) {
$identity->SetEmail($account->Email());
}
$result[] = $identity;
}
@ -48,12 +50,12 @@ class FileIdentities implements IIdentities
/**
* @inheritDoc
*/
public function SetIdentities(Account $account, array $identities)
public function SetIdentities(Account $account, array $identities): void
{
$jsons = array_map(function ($identity) {
$jsons = \array_map(function ($identity) {
return $identity->ToSimpleJSON();
}, $identities);
$this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', json_encode($jsons));
$this->localStorageProvider->Put($account, Storage\Enumerations\StorageType::CONFIG, 'identities', \json_encode($jsons));
}
/**
@ -68,4 +70,4 @@ class FileIdentities implements IIdentities
{
return "File";
}
}
}

View file

@ -20,7 +20,7 @@ interface IIdentities
*
* @return void
*/
public function SetIdentities(Account $account, array $identities);
public function SetIdentities(Account $account, array $identities): void;
/**
* @return bool
@ -31,4 +31,4 @@ interface IIdentities
* @return string
*/
public function Name(): string;
}
}

View file

@ -27,7 +27,7 @@ class TestIdentities implements IIdentities
* @return void
* @throws Exception
*/
public function SetIdentities(Account $account, array $identities)
public function SetIdentities(Account $account, array $identities): void
{
throw new Exception("Not implemented");
}
@ -44,4 +44,4 @@ class TestIdentities implements IIdentities
{
return "Test";
}
}
}