ILIAS  release_8 Revision v8.24
class.ilRegistrationSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public const ERR_UNKNOWN_RCP = 1;
29 public const ERR_MISSING_RCP = 2;
30
31 public const REG_HASH_LIFETIME_MIN_VALUE = 60;
32
33 public const IL_REG_DISABLED = 1;
34 public const IL_REG_DIRECT = 2;
35 public const IL_REG_APPROVE = 3;
36 public const IL_REG_ACTIVATION = 4;
37 public const IL_REG_CODES = 5;
38 public const IL_REG_ROLE_UNDEFINED = 0;
39 public const IL_REG_ROLES_FIXED = 1;
40 public const IL_REG_ROLES_EMAIL = 2;
41 public const IL_REG_ERROR_UNKNOWN = 1;
42 public const IL_REG_ERROR_NO_PERM = 2;
43
44 private int $registration_type;
45 private bool $password_generation_enabled = false;
46 private bool $access_limitation = false;
47 private string $approve_recipient_logins = '';
48 private array $approve_recipient_ids = [];
50 private array $unknown = [];
51 private int $reg_hash_life_time = 0;
52 private bool $reg_allow_codes = false;
53 private array $allowed_domains = [];
54
56
57 public function __construct()
58 {
59 global $DIC;
60
61 $this->settings = $DIC->settings();
62 $this->read();
63 }
64
65 public function getRegistrationType(): int
66 {
68 }
69
70 public function setRegistrationType(int $a_type): void
71 {
72 $this->registration_type = $a_type;
73 }
74
75 public static function _lookupRegistrationType(): int
76 {
77 global $DIC;
78
79 $ilSetting = $DIC['ilSetting'];
80 $ret = (int) $ilSetting->get('new_registration_type', (string) self::IL_REG_DISABLED);
81
82 if ($ret < 1 || $ret > 5) {
83 //data is corrupted and should be processed like "No Registration possible" (#18261)
85 }
86 return $ret;
87 }
88
89 public function enabled(): bool
90 {
91 return $this->registration_type !== self::IL_REG_DISABLED;
92 }
93
94 public function directEnabled(): bool
95 {
96 return $this->registration_type === self::IL_REG_DIRECT;
97 }
98
99 public function approveEnabled(): bool
100 {
101 return $this->registration_type === self::IL_REG_APPROVE;
102 }
103
104 public function activationEnabled(): bool
105 {
106 return $this->registration_type === self::IL_REG_ACTIVATION;
107 }
108
109 public function registrationCodeRequired(): bool
110 {
111 return $this->registration_type === self::IL_REG_CODES;
112 }
113
114 public function passwordGenerationEnabled(): bool
115 {
117 }
118
119 public function setPasswordGenerationStatus(bool $a_status): void
120 {
121 $this->password_generation_enabled = $a_status;
122 }
123
124 public function getAccessLimitation(): bool
125 {
127 }
128
129 public function setAccessLimitation(bool $a_access_limitation): void
130 {
131 $this->access_limitation = $a_access_limitation;
132 }
133
134 public function setApproveRecipientLogins(string $a_rec_string): void
135 {
136 $this->approve_recipient_logins = $a_rec_string;
137 $this->approve_recipient_ids = [];
138
139 // convert logins to array of ids
140 foreach (explode(',', trim($this->approve_recipient_logins)) as $login) {
141 if ($uid = ilObjUser::_lookupId(trim($login))) {
142 $this->approve_recipient_ids[] = $uid;
143 }
144 }
145 }
146
147 public function getApproveRecipientLogins(): string
148 {
150 }
151
152 public function getApproveRecipients(): array
153 {
155 }
156
157 public function getUnknown(): string
158 {
159 return implode(',', $this->unknown);
160 }
161
162 public function roleSelectionEnabled(): bool
163 {
164 return $this->role_type === self::IL_REG_ROLES_FIXED;
165 }
166
167 public function automaticRoleAssignmentEnabled(): bool
168 {
169 return $this->role_type === self::IL_REG_ROLES_EMAIL;
170 }
171
172 public function setRoleType(int $a_type): void
173 {
174 $this->role_type = $a_type;
175 }
176
177 public function setRegistrationHashLifetime(int $a_lifetime): self
178 {
179 $this->reg_hash_life_time = $a_lifetime;
180 return $this;
181 }
182
184 {
185 return max($this->reg_hash_life_time, self::REG_HASH_LIFETIME_MIN_VALUE);
186 }
187
188 public function setAllowCodes(bool $a_allow_codes): self
189 {
190 $this->reg_allow_codes = $a_allow_codes;
191
192 return $this;
193 }
194
195 public function getAllowCodes(): bool
196 {
198 }
199
200 public function setAllowedDomains(string $a_value): void
201 {
202 $a_value = array_map(
203 static function (string $value): string {
204 return trim($value);
205 },
206 explode(";", trim($a_value))
207 );
208
209 $this->allowed_domains = $a_value;
210 }
211
212 public function getAllowedDomains(): array
213 {
215 }
216
217 public function validate(): int
218 {
219 $this->unknown = [];
220
221 $login_arr = explode(',', $this->getApproveRecipientLogins());
222 $login_arr = $login_arr ?: [];
223 $valid = [];
224 foreach ($login_arr as $recipient) {
225 if (!$recipient = trim($recipient)) {
226 continue;
227 }
228 if (!ilObjUser::_lookupId($recipient)) {
229 $this->unknown[] = $recipient;
230 } else {
231 $valid[] = $recipient;
232 }
233 }
234 if (count($this->unknown)) {
236 }
237 if ($this->getRegistrationType() === self::IL_REG_APPROVE && !count($valid)) {
239 }
240 return 0;
241 }
242
243 public function save(): bool
244 {
245 $this->settings->set('reg_role_assignment', (string) $this->role_type);
246 $this->settings->set('new_registration_type', (string) $this->registration_type);
247 $this->settings->set('passwd_reg_auto_generate', (string) $this->password_generation_enabled);
248 $this->settings->set('approve_recipient', addslashes(serialize($this->approve_recipient_ids)));
249 $this->settings->set('reg_access_limitation', (string) $this->access_limitation);
250 $this->settings->set('reg_hash_life_time', (string) $this->reg_hash_life_time);
251 $this->settings->set('reg_allow_codes', (string) $this->reg_allow_codes);
252 $this->settings->set('reg_allowed_domains', implode(';', $this->allowed_domains));
253 return true;
254 }
255
256 private function read(): void
257 {
258 //static method validates value
259 $this->registration_type = self::_lookupRegistrationType();
260
261 $this->role_type = (int) $this->settings->get('reg_role_assignment', '1');
262 $this->password_generation_enabled = (bool) $this->settings->get('passwd_reg_auto_generate');
263 $this->access_limitation = (bool) $this->settings->get('reg_access_limitation');
264 $this->reg_hash_life_time = (int) $this->settings->get('reg_hash_life_time');
265 $this->reg_allow_codes = (bool) $this->settings->get('reg_allow_codes');
266
267 $this->approve_recipient_ids = unserialize(
268 stripslashes($this->settings->get('approve_recipient', "")),
269 ['allowed_classes' => false]
270 ) ?: [];
271
272 // create login array
273 $tmp_logins = [];
274 foreach ($this->approve_recipient_ids as $id) {
275 if ($login = ilObjUser::_lookupLogin((int) $id)) {
276 $tmp_logins[] = $login;
277 }
278 }
279 $this->approve_recipient_logins = implode(',', $tmp_logins);
280 $this->setAllowedDomains((string) $this->settings->get('reg_allowed_domains'));
281 }
282}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupId($a_user_str)
static _lookupLogin(int $a_user_id)
Class ilObjAuthSettingsGUI.
setApproveRecipientLogins(string $a_rec_string)
setAccessLimitation(bool $a_access_limitation)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$valid
global $DIC
Definition: feed.php:28
global $ilSetting
Definition: privfeed.php:17