ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl Class Reference
+ Inheritance diagram for ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl:
+ Collaboration diagram for ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl:

Public Member Functions

 __construct (private \ilRegistrationSettings $settings, private PendingRegistrationRepository $pending_reg_repository, private \ilDBInterface $db, private \ilComponentLogger $logger, private ClockFactory $clock_factory)
 
 distributeMailsOnRegistration (\ilObjUser $user)
 
 deleteExpiredUserObjects (int $usr_id)
 
- Public Member Functions inherited from ILIAS\Registration\DualOptIn\Service\DualOptInService
 verifyHashAndActivateUser (PendingRegistrationHash $hash)
 
 distributeMailsOnRegistration (\ilObjUser $user)
 
 deleteExpiredUserObjects (int $usr_id)
 

Data Fields

const string ID = 'reg_hash_service'
 

Private Member Functions

 findConfirmableRegistration (PendingRegistrationHash $hash)
 
 createPendingRegistration (int $usr_id)
 
 activateUser (\ilObjUser $user)
 
 triggerExpiredUserCleanup (PendingRegistration $expired_reg)
 
 sendRegistrationMail (\ilObjUser $user, string $password)
 

Detailed Description

Definition at line 34 of file DualOptInServiceImpl.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::__construct ( private \ilRegistrationSettings  $settings,
private PendingRegistrationRepository  $pending_reg_repository,
private \ilDBInterface  $db,
private \ilComponentLogger  $logger,
private ClockFactory  $clock_factory 
)

Definition at line 38 of file DualOptInServiceImpl.php.

44 {
45 }

Member Function Documentation

◆ activateUser()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::activateUser ( \ilObjUser  $user)
private

Definition at line 183 of file DualOptInServiceImpl.php.

183 : void
184 {
185 $user->setActive(true);
186
187 $password = '';
188 if ($this->settings->passwordGenerationEnabled()) {
190 $user->setPasswd($password, \ilObjUser::PASSWD_PLAIN);
191 $user->setLastPasswordChangeTS($this->clock_factory->utc()->now()->getTimestamp());
192 }
193
194 $user->update();
195
196 $this->sendRegistrationMail($user, $password);
197 }
const PASSWD_PLAIN
static generatePasswords(int $a_number)
Generate a number of passwords.

References ilSecuritySettingsChecker\generatePasswords(), ilObjUser\PASSWD_PLAIN, ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\sendRegistrationMail(), ilObjUser\setActive(), ilObjUser\setLastPasswordChangeTS(), ilObjUser\setPasswd(), ILIAS\Repository\settings(), and ilObjUser\update().

+ Here is the call graph for this function:

◆ createPendingRegistration()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::createPendingRegistration ( int  $usr_id)
private

Definition at line 105 of file DualOptInServiceImpl.php.

106 {
107 $pending_reg = new PendingRegistration(
108 $this->pending_reg_repository->nextIdentity(),
109 new ObjectId($usr_id),
110 $this->pending_reg_repository->findNewHash(),
111 $this->clock_factory->utc()->now()
112 );
113 $this->pending_reg_repository->store($pending_reg);
114
115 return $pending_reg;
116 }

Referenced by ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\distributeMailsOnRegistration().

+ Here is the caller graph for this function:

◆ deleteExpiredUserObjects()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::deleteExpiredUserObjects ( int  $usr_id)

Implements ILIAS\Registration\DualOptIn\Service\DualOptInService.

Definition at line 118 of file DualOptInServiceImpl.php.

118 : void
119 {
120 $this->logger->debug(
121 'Started deletion of inactive user objects with expired confirmation hash values (dual opt in) ...'
122 );
123
124 $lifetime = $this->settings->getRegistrationHashLifetime();
125 if ($lifetime <= 0) {
126 $this->logger->debug('Registration hash lifetime is <= 0, skipping deletion.');
127 return;
128 }
129
130 $now = $this->clock_factory->utc()->now();
131 $interval = new \DateInterval("PT{$lifetime}S");
132 $cutoff = $now->sub($interval);
133
134 $expired_regs = array_filter(
135 array_map(
136 static fn(PendingRegistration $reg): PendingRegistration => $reg->withEvaluatedState($now, $lifetime),
137 $this->pending_reg_repository->findExpired($cutoff->getTimestamp(), $usr_id)
138 ),
139 static fn(PendingRegistration $reg): bool => $reg->isExpired()
140 );
141
142 $this->logger->info(
143 \sprintf(
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),
147 $lifetime
148 )
149 );
150
151 $this->pending_reg_repository->delete(...$expired_regs);
152
153 $num_deleted_users = 0;
154 foreach ($expired_regs as $expired_reg) {
155 $user = \ilObjectFactory::getInstanceByObjId($expired_reg->userId()->toInt(), false);
156 if (!($user instanceof \ilObjUser)) {
157 continue;
158 }
159
160 $this->logger->info(
161 \sprintf(
162 'Deleting user (login: %s | id: %d) – expired dual opt-in (created: %s, cutoff: %s, lifetime: %d s)',
163 $user->getLogin(),
164 $user->getId(),
165 $expired_reg->createdAt()->format(\DateTimeInterface::ATOM),
166 $cutoff->format(\DateTimeInterface::ATOM),
167 $lifetime
168 )
169 );
170
171 $user->delete();
172 ++$num_deleted_users;
173 }
174
175 $this->logger->info(
176 \sprintf(
177 '%d inactive user objects with expired confirmation hash values (dual opt-in) deleted.',
178 $num_deleted_users
179 )
180 );
181 }
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id

References ilObjectFactory\getInstanceByObjId(), ILIAS\Registration\DualOptIn\Entity\PendingRegistration\isExpired(), ILIAS\Repository\logger(), ILIAS\Repository\settings(), and ILIAS\Registration\DualOptIn\Entity\PendingRegistration\withEvaluatedState().

+ Here is the call graph for this function:

◆ distributeMailsOnRegistration()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::distributeMailsOnRegistration ( \ilObjUser  $user)

Implements ILIAS\Registration\DualOptIn\Service\DualOptInService.

Definition at line 92 of file DualOptInServiceImpl.php.

92 : void
93 {
94 $pending_reg = $this->createPendingRegistration($user->getId());
95
96 $mail = new DualOptInMail(
97 $user,
98 $pending_reg,
99 $this->settings->getRegistrationHashLifetime()
100 );
101 $mail->setRecipients([$user]);
102 $mail->send();
103 }

References ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\createPendingRegistration(), ilObject\getId(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ findConfirmableRegistration()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::findConfirmableRegistration ( PendingRegistrationHash  $hash)
private
Exceptions
PendingRegistrationNotFoundException
PendingRegistrationExpiredException
PendingRegistrationAlreadyConfirmedException

Definition at line 67 of file DualOptInServiceImpl.php.

68 {
69 $pending_reg = $this->pending_reg_repository->findByHashValue($hash->toString());
70 if ($pending_reg === null) {
71 throw new PendingRegistrationNotFoundException();
72 }
73
74 $lifetime = $this->settings->getRegistrationHashLifetime();
75 $pending_reg = $pending_reg->withEvaluatedState(
76 $this->clock_factory->utc()->now(),
77 $lifetime > 0 ? $lifetime : null
78 );
79
80 if ($pending_reg->isConfirmed()) {
81 throw new PendingRegistrationAlreadyConfirmedException();
82 }
83
84 if ($pending_reg->isExpired()) {
85 $this->triggerExpiredUserCleanup($pending_reg);
86 throw new PendingRegistrationExpiredException();
87 }
88
89 return $pending_reg;
90 }

References ILIAS\Repository\settings(), ILIAS\Registration\DualOptIn\ValueObjects\PendingRegistrationHash\toString(), and ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\triggerExpiredUserCleanup().

+ Here is the call graph for this function:

◆ sendRegistrationMail()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::sendRegistrationMail ( \ilObjUser  $user,
string  $password 
)
private

Definition at line 215 of file DualOptInServiceImpl.php.

215 : void
216 {
217 $account_mail = (new \ilAccountRegistrationMail(
218 $this->settings,
220 new NewAccountMailRepository($this->db)
221 ))->withEmailConfirmationRegistrationMode();
222
223 if ($user->getPref('reg_target') ?? '') {
224 $account_mail = $account_mail->withPermanentLinkTarget($user->getPref('reg_target'));
225 }
226
227 $account_mail->send($user, $password);
228 }
static getLogger(string $a_component_id)
Get component logger.

References ilLoggerFactory\getLogger(), ilObjUser\getPref(), and ILIAS\Repository\settings().

Referenced by ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\activateUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ triggerExpiredUserCleanup()

ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::triggerExpiredUserCleanup ( PendingRegistration  $expired_reg)
private

Definition at line 199 of file DualOptInServiceImpl.php.

199 : void
200 {
201 $soap_client = new \ilSoapClient();
202 $soap_client->setResponseTimeout(1);
203 $soap_client->enableWSDL(true);
204 $soap_client->init();
205
206 $this->logger->info(
207 'Triggered soap call (background process) for deletion of inactive ' .
208 'user objects with expired confirmation hash values (dual opt in) ...'
209 );
210
211 $sid = session_id() . '::' . CLIENT_ID;
212 $soap_client->call('deleteExpiredDualOptInUserObjects', [$sid, $expired_reg->userId()->toInt()]);
213 }
const CLIENT_ID
Definition: constants.php:41

References CLIENT_ID, ILIAS\Repository\logger(), and ILIAS\Registration\DualOptIn\Entity\PendingRegistration\userId().

Referenced by ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl\findConfirmableRegistration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ ID

const string ILIAS\Registration\DualOptIn\Service\DualOptInServiceImpl::ID = 'reg_hash_service'

Definition at line 36 of file DualOptInServiceImpl.php.


The documentation for this class was generated from the following file: