ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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(?ilSetting $settings = null)
58 {
59 global $DIC;
60
61 if (null == $settings) {
62 $settings = $DIC->settings();
63 }
64
65 $this->settings = $settings;
66 $this->read();
67 }
68
69 public function getRegistrationType(): int
70 {
72 }
73
74 public function setRegistrationType(int $a_type): void
75 {
76 $this->registration_type = $a_type;
77 }
78
79 public static function _lookupRegistrationType(): int
80 {
81 global $DIC;
82
83 $ilSetting = $DIC['ilSetting'];
84 $ret = (int) $ilSetting->get('new_registration_type', (string) self::IL_REG_DISABLED);
85
86 if ($ret < 1 || $ret > 5) {
87 //data is corrupted and should be processed like "No Registration possible" (#18261)
89 }
90 return $ret;
91 }
92
93 public function enabled(): bool
94 {
95 return $this->registration_type !== self::IL_REG_DISABLED;
96 }
97
98 public function directEnabled(): bool
99 {
100 return $this->registration_type === self::IL_REG_DIRECT;
101 }
102
103 public function approveEnabled(): bool
104 {
105 return $this->registration_type === self::IL_REG_APPROVE;
106 }
107
108 public function activationEnabled(): bool
109 {
110 return $this->registration_type === self::IL_REG_ACTIVATION;
111 }
112
113 public function registrationCodeRequired(): bool
114 {
115 return $this->registration_type === self::IL_REG_CODES;
116 }
117
118 public function passwordGenerationEnabled(): bool
119 {
121 }
122
123 public function setPasswordGenerationStatus(bool $a_status): void
124 {
125 $this->password_generation_enabled = $a_status;
126 }
127
128 public function getAccessLimitation(): bool
129 {
131 }
132
133 public function setAccessLimitation(bool $a_access_limitation): void
134 {
135 $this->access_limitation = $a_access_limitation;
136 }
137
138 public function setApproveRecipientLogins(string $a_rec_string): void
139 {
140 $this->approve_recipient_logins = $a_rec_string;
141 $this->approve_recipient_ids = [];
142
143 // convert logins to array of ids
144 foreach (explode(',', trim($this->approve_recipient_logins)) as $login) {
145 if ($uid = ilObjUser::_lookupId(trim($login))) {
146 $this->approve_recipient_ids[] = $uid;
147 }
148 }
149 }
150
151 public function getApproveRecipientLogins(): string
152 {
154 }
155
156 public function getApproveRecipients(): array
157 {
159 }
160
161 public function getUnknown(): string
162 {
163 return implode(',', $this->unknown);
164 }
165
166 public function roleSelectionEnabled(): bool
167 {
168 return $this->role_type === self::IL_REG_ROLES_FIXED;
169 }
170
171 public function automaticRoleAssignmentEnabled(): bool
172 {
173 return $this->role_type === self::IL_REG_ROLES_EMAIL;
174 }
175
176 public function setRoleType(int $a_type): void
177 {
178 $this->role_type = $a_type;
179 }
180
181 public function setRegistrationHashLifetime(int $a_lifetime): self
182 {
183 $this->reg_hash_life_time = $a_lifetime;
184 return $this;
185 }
186
188 {
189 return max($this->reg_hash_life_time, self::REG_HASH_LIFETIME_MIN_VALUE);
190 }
191
192 public function setAllowCodes(bool $a_allow_codes): self
193 {
194 $this->reg_allow_codes = $a_allow_codes;
195
196 return $this;
197 }
198
199 public function getAllowCodes(): bool
200 {
202 }
203
204 public function setAllowedDomains(string $a_value): void
205 {
206 $a_value = array_map(
207 static function (string $value): string {
208 return trim($value);
209 },
210 explode(";", trim($a_value))
211 );
212
213 $this->allowed_domains = $a_value;
214 }
215
216 public function getAllowedDomains(): array
217 {
219 }
220
221 public function validate(): int
222 {
223 $this->unknown = [];
224
225 $login_arr = explode(',', $this->getApproveRecipientLogins());
226 $login_arr = $login_arr ?: [];
227 $valid = [];
228 foreach ($login_arr as $recipient) {
229 if (!$recipient = trim($recipient)) {
230 continue;
231 }
232 if (!ilObjUser::_lookupId($recipient)) {
233 $this->unknown[] = $recipient;
234 } else {
235 $valid[] = $recipient;
236 }
237 }
238 if (count($this->unknown)) {
240 }
241 if ($this->getRegistrationType() === self::IL_REG_APPROVE && !count($valid)) {
243 }
244 return 0;
245 }
246
247 public function save(): bool
248 {
249 $this->settings->set('reg_role_assignment', (string) $this->role_type);
250 $this->settings->set('new_registration_type', (string) $this->registration_type);
251 $this->settings->set('passwd_reg_auto_generate', (string) $this->password_generation_enabled);
252 $this->settings->set('approve_recipient', addslashes(serialize($this->approve_recipient_ids)));
253 $this->settings->set('reg_access_limitation', (string) $this->access_limitation);
254 $this->settings->set('reg_hash_life_time', (string) $this->reg_hash_life_time);
255 $this->settings->set('reg_allow_codes', (string) $this->reg_allow_codes);
256 $this->settings->set('reg_allowed_domains', implode(';', $this->allowed_domains));
257 return true;
258 }
259
260 private function read(): void
261 {
262 //static method validates value
263 $this->registration_type = self::_lookupRegistrationType();
264
265 $this->role_type = (int) $this->settings->get('reg_role_assignment', '1');
266 $this->password_generation_enabled = (bool) $this->settings->get('passwd_reg_auto_generate');
267 $this->access_limitation = (bool) $this->settings->get('reg_access_limitation');
268 $this->reg_hash_life_time = (int) $this->settings->get('reg_hash_life_time');
269 $this->reg_allow_codes = (bool) $this->settings->get('reg_allow_codes');
270
271 $this->approve_recipient_ids = unserialize(
272 stripslashes($this->settings->get('approve_recipient', serialize([]))),
273 ['allowed_classes' => false]
274 ) ?: [];
275
276 // create login array
277 $tmp_logins = [];
278 foreach ($this->approve_recipient_ids as $id) {
279 if ($login = ilObjUser::_lookupLogin((int) $id)) {
280 $tmp_logins[] = $login;
281 }
282 }
283 $this->approve_recipient_logins = implode(',', $tmp_logins);
284 $this->setAllowedDomains((string) $this->settings->get('reg_allowed_domains'));
285 }
286}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupId(string|array $a_user_str)
static _lookupLogin(int $a_user_id)
Class ilObjAuthSettingsGUI.
setApproveRecipientLogins(string $a_rec_string)
__construct(?ilSetting $settings=null)
setAccessLimitation(bool $a_access_limitation)
ILIAS Setting Class.
$valid
global $ilSetting
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26