adasdas
This commit is contained in:
@@ -38,28 +38,62 @@ final class AccountGate
|
||||
];
|
||||
}
|
||||
|
||||
$user = $this->ldap->getUserByUsername($username, ['uid', 'shadowExpire']);
|
||||
$user = $this->ldap->getUserByUsername($username, ['uid', 'shadowExpire', 'memberOf']);
|
||||
|
||||
if (!is_array($user)) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'state' => 'blocked',
|
||||
'message' => 'Dieses Konto ist nicht freigeschaltet.',
|
||||
];
|
||||
}
|
||||
|
||||
$shadowExpire = (string) ($user['shadowexpire'] ?? $user['shadowExpire'] ?? '');
|
||||
$activeShadowExpire = (string) ($this->config['ldap']['active_shadow_expire'] ?? -1);
|
||||
$pendingGroupDn = strtolower(trim((string) ($this->config['ldap']['pending_group_dn'] ?? '')));
|
||||
$memberOf = $this->normalizeMemberOf($user['memberof'] ?? $user['memberOf'] ?? []);
|
||||
$isPending = $pendingGroupDn !== '' && in_array($pendingGroupDn, $memberOf, true);
|
||||
|
||||
if ($shadowExpire !== $activeShadowExpire) {
|
||||
if ($isPending && $shadowExpire !== $activeShadowExpire) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'state' => 'pending',
|
||||
'message' => 'Dieses Konto ist noch nicht freigeschaltet.',
|
||||
];
|
||||
}
|
||||
|
||||
if ($shadowExpire !== '' && $shadowExpire !== $activeShadowExpire) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'state' => 'blocked',
|
||||
'message' => 'Dieses Konto ist derzeit deaktiviert.',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'allowed' => true,
|
||||
'state' => 'active',
|
||||
'message' => 'Konto ist aktiv.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function normalizeMemberOf(mixed $value): array
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = [$value];
|
||||
}
|
||||
|
||||
if (!is_array($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_map(
|
||||
static fn (mixed $item): string => strtolower(trim((string) $item)),
|
||||
$value
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,14 @@ final class RegistrationService
|
||||
return $this->store->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function findLatestByUsername(string $username): ?array
|
||||
{
|
||||
return $this->store->findLatestByUsername($username);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $input
|
||||
* @return array{success: bool, errors?: array<int, string>, request?: array<string, mixed>}
|
||||
|
||||
@@ -42,6 +42,37 @@ final class RegistrationStore
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function findLatestByUsername(string $username): ?array
|
||||
{
|
||||
$username = strtolower(trim($username));
|
||||
|
||||
if ($username === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$matches = array_values(array_filter(
|
||||
$this->read(),
|
||||
static fn (array $item): bool => strtolower((string) ($item['username'] ?? '')) === $username
|
||||
));
|
||||
|
||||
if ($matches === []) {
|
||||
return null;
|
||||
}
|
||||
|
||||
usort(
|
||||
$matches,
|
||||
static fn (array $left, array $right): int => strcmp(
|
||||
(string) ($right['created_at'] ?? ''),
|
||||
(string) ($left['created_at'] ?? '')
|
||||
)
|
||||
);
|
||||
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user