19declare(strict_types=1);
36 public const string ID =
'reg_hash_service';
55 $this->pending_reg_repository->delete(
56 $pending_reg->withConfirmed()
69 $pending_reg = $this->pending_reg_repository->findByHashValue($hash->
toString());
70 if ($pending_reg ===
null) {
74 $lifetime = $this->
settings->getRegistrationHashLifetime();
75 $pending_reg = $pending_reg->withEvaluatedState(
76 $this->clock_factory->utc()->now(),
77 $lifetime > 0 ? $lifetime :
null
80 if ($pending_reg->isConfirmed()) {
84 if ($pending_reg->isExpired()) {
99 $this->
settings->getRegistrationHashLifetime()
101 $mail->setRecipients([$user]);
108 $this->pending_reg_repository->nextIdentity(),
110 $this->pending_reg_repository->findNewHash(),
111 $this->clock_factory->utc()->now()
113 $this->pending_reg_repository->store($pending_reg);
121 'Started deletion of inactive user objects with expired confirmation hash values (dual opt in) ...'
124 $lifetime = $this->
settings->getRegistrationHashLifetime();
125 if ($lifetime <= 0) {
126 $this->
logger->debug(
'Registration hash lifetime is <= 0, skipping deletion.');
130 $now = $this->clock_factory->utc()->now();
131 $interval = new \DateInterval(
"PT{$lifetime}S");
132 $cutoff = $now->sub($interval);
134 $expired_regs = array_filter(
137 $this->pending_reg_repository->findExpired($cutoff->getTimestamp(), $usr_id)
144 '%d inactive user objects eligible for deletion found and deleted (cutoff: %s, lifetime: %d s).',
145 \count($expired_regs),
146 $cutoff->format(\DateTimeInterface::ATOM),
151 $this->pending_reg_repository->delete(...$expired_regs);
153 $num_deleted_users = 0;
154 foreach ($expired_regs as $expired_reg) {
162 'Deleting user (login: %s | id: %d) – expired dual opt-in (created: %s, cutoff: %s, lifetime: %d s)',
165 $expired_reg->createdAt()->format(\DateTimeInterface::ATOM),
166 $cutoff->format(\DateTimeInterface::ATOM),
172 ++$num_deleted_users;
177 '%d inactive user objects with expired confirmation hash values (dual opt-in) deleted.',
188 if ($this->
settings->passwordGenerationEnabled()) {
201 $soap_client = new \ilSoapClient();
202 $soap_client->setResponseTimeout(1);
203 $soap_client->enableWSDL(
true);
204 $soap_client->init();
207 'Triggered soap call (background process) for deletion of inactive ' .
208 'user objects with expired confirmation hash values (dual opt in) ...'
212 $soap_client->call(
'deleteExpiredDualOptInUserObjects', [$sid, $expired_reg->
userId()->toInt()]);
217 $account_mail = (new \ilAccountRegistrationMail(
220 new NewAccountMailRepository($this->db)
221 ))->withEmailConfirmationRegistrationMode();
223 if ($user->
getPref(
'reg_target') ??
'') {
224 $account_mail = $account_mail->withPermanentLinkTarget($user->
getPref(
'reg_target'));
227 $account_mail->send($user, $password);
withEvaluatedState(\DateTimeImmutable $now, ?int $validity_in_seconds)
sendRegistrationMail(\ilObjUser $user, string $password)
distributeMailsOnRegistration(\ilObjUser $user)
triggerExpiredUserCleanup(PendingRegistration $expired_reg)
findConfirmableRegistration(PendingRegistrationHash $hash)
createPendingRegistration(int $usr_id)
__construct(private \ilRegistrationSettings $settings, private PendingRegistrationRepository $pending_reg_repository, private \ilDBInterface $db, private \ilComponentLogger $logger, private ClockFactory $clock_factory)
deleteExpiredUserObjects(int $usr_id)
activateUser(\ilObjUser $user)
Component logger with individual log levels by component id.
static getLogger(string $a_component_id)
Get component logger.
setLastPasswordChangeTS(int $a_last_password_change_ts)
setPasswd(string $a_str, string $a_type=ilObjUser::PASSWD_PLAIN)
setActive(bool $active, int $owner=0)
set user active state and updates system fields appropriately
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
Class ilObjAuthSettingsGUI.
static generatePasswords(int $a_number)
Generate a number of passwords.
verifyHashAndActivateUser(PendingRegistrationHash $hash)