dadasd
This commit is contained in:
65
src/App/AccountGate.php
Normal file
65
src/App/AccountGate.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class AccountGate
|
||||
{
|
||||
private LdapProvisioner $ldap;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $config,
|
||||
) {
|
||||
$this->ldap = new LdapProvisioner($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{allowed: bool, message: string}
|
||||
*/
|
||||
public function checkUsername(string $username): array
|
||||
{
|
||||
$username = strtolower(trim($username));
|
||||
|
||||
if ($username === '') {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'message' => 'Für dieses Konto konnte kein Benutzername ermittelt werden.',
|
||||
];
|
||||
}
|
||||
|
||||
if (!$this->ldap->isEnabled() || !$this->ldap->canUseLdap()) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'message' => 'Der Kontostatus konnte nicht sicher geprüft werden.',
|
||||
];
|
||||
}
|
||||
|
||||
$user = $this->ldap->getUserByUsername($username, ['uid', 'shadowExpire']);
|
||||
|
||||
if (!is_array($user)) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'message' => 'Dieses Konto ist nicht freigeschaltet.',
|
||||
];
|
||||
}
|
||||
|
||||
$shadowExpire = (string) ($user['shadowexpire'] ?? $user['shadowExpire'] ?? '');
|
||||
$activeShadowExpire = (string) ($this->config['ldap']['active_shadow_expire'] ?? -1);
|
||||
|
||||
if ($shadowExpire !== $activeShadowExpire) {
|
||||
return [
|
||||
'allowed' => false,
|
||||
'message' => 'Dieses Konto ist noch nicht freigeschaltet.',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'allowed' => true,
|
||||
'message' => 'Konto ist aktiv.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,8 @@ final class RegistrationService
|
||||
$note = trim((string) ($input['note'] ?? ''));
|
||||
$password = (string) ($input['password'] ?? '');
|
||||
$passwordConfirm = (string) ($input['password_confirm'] ?? '');
|
||||
$displayName = trim($givenName . ' ' . $familyName);
|
||||
$displayName = $givenName;
|
||||
$fullName = trim($givenName . ' ' . $familyName);
|
||||
$errors = [];
|
||||
|
||||
if (!preg_match('/^[a-z0-9._-]{3,32}$/', $username)) {
|
||||
@@ -128,7 +129,7 @@ final class RegistrationService
|
||||
'apple_generateduid' => '',
|
||||
'display_name' => $displayName,
|
||||
'cn' => $displayName !== '' ? $displayName : $username,
|
||||
'gecos' => $displayName,
|
||||
'gecos' => $fullName !== '' ? $fullName : $displayName,
|
||||
'admin_note' => '',
|
||||
'ldap_created_at' => gmdate('c'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user