229 {
231 $form_valid = $this->
form->checkInput();
232
233
234 $valid_code = $valid_role = false;
235
236
237 if ($this->code_enabled) {
238 $code = $this->
form->getInput(
'usr_registration_code');
239
240 if (
241 $code !== '' ||
242 $this->registration_settings->registrationCodeRequired()
243 ) {
244
246 $code_obj = $this->
form->getItemByPostVar(
'usr_registration_code');
247 $code_obj->setAlert($this->
lng->txt(
'registration_code_not_valid'));
248 $form_valid = false;
249 } else {
250 $valid_code = true;
251
252
254 if ($role_id && $this->rbacreview->isGlobalRole($role_id)) {
255 $valid_role = $role_id;
256 }
257 }
258 }
259 }
260
261
262 if (!$valid_code) {
263
266
267 $domains = [];
268 foreach ($this->registration_settings->getAllowedDomains() as $item) {
269 if (trim($item)) {
270 $domains[] = $item;
271 }
272 }
273 if (count($domains)) {
274 $mail_valid = false;
275 foreach ($domains as $domain) {
276 $domain = str_replace("*", "~~~", $domain);
277 $domain = preg_quote($domain, '/');
278 $domain = str_replace("~~~", ".+", $domain);
279 if (preg_match(
"/^" . $domain .
"$/",
$email, $hit)) {
280 $mail_valid = true;
281 break;
282 }
283 }
284 if (!$mail_valid) {
285 $mail_obj = $this->
form->getItemByPostVar(
'usr_email');
286 $mail_obj->setAlert(sprintf(
287 $this->
lng->txt(
"reg_email_domains"),
288 implode(", ", $domains)
289 ));
290 $form_valid = false;
291 }
292 }
293 }
294 }
295
296 $error_lng_var = '';
297 if (
298 !$this->registration_settings->passwordGenerationEnabled() &&
300 $this->form->getInput('usr_password'),
301 $this->form->getInput('username'),
302 $error_lng_var
303 )
304 ) {
305 $passwd_obj = $this->
form->getItemByPostVar(
'usr_password');
306 $passwd_obj->setAlert($this->
lng->txt($error_lng_var));
307 $form_valid = false;
308 }
309
310 $showGlobalTermsOfServieFailure = false;
312 $agr_obj = $this->
form->getItemByPostVar(
'accept_terms_of_service');
313 if ($agr_obj) {
314 $agr_obj->setAlert($this->
lng->txt(
'force_accept_usr_agreement'));
315 $form_valid = false;
316 } else {
317 $showGlobalTermsOfServieFailure = true;
318 }
319 }
320
321
322 if (!$valid_role) {
323
324 if ($this->registration_settings->roleSelectionEnabled()) {
325 $selected_role = $this->
form->getInput(
"usr_roles");
327 $valid_role = (
int) $selected_role;
328 }
329 }
330 else {
332 $valid_role = $registration_role_assignments->getRoleByEmail($this->
form->getInput(
"usr_email"));
333 }
334 }
335
336
337 if (!$valid_role) {
338 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"registration_no_valid_role"));
339 $form_valid = false;
340 }
341
342
343 $login_obj = $this->
form->getItemByPostVar(
'username');
344 $login = $this->
form->getInput(
"username");
346 $login_obj->setAlert($this->
lng->txt(
"login_invalid"));
347 $form_valid = false;
348 }
349
350 if ($form_valid) {
352 $login_obj->setAlert($this->
lng->txt(
"login_exists"));
353 $form_valid = false;
354 } elseif ((
int) $this->
settings->get(
'allow_change_loginname') &&
355 (int) $this->settings->get('reuse_of_loginnames') === 0 &&
357 $login_obj->setAlert($this->
lng->txt(
'login_exists'));
358 $form_valid = false;
359 }
360 }
361
362 if (!$form_valid) {
363 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
364 } elseif ($showGlobalTermsOfServieFailure) {
365 $this->
lng->loadLanguageModule(
'tos');
366 $this->tpl->setOnScreenMessage('failure', sprintf(
367 $this->
lng->txt(
'tos_account_reg_not_possible'),
369 ));
370 } else {
371 $password = $this->createUser($valid_role);
373 return $this->
login();
374 }
375 $this->
form->setValuesByPost();
377 }
distributeMails(string $password)
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not
static _loginExists(string $a_login, int $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
static _doesLoginnameExistInHistory(string $a_login)
Checks whether the passed loginname already exists in history.
static getCodeRole(string $code)
static isValidRegistrationCode(string $a_code)
Class class.ilregistrationEmailRoleAssignments.
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
static isLogin(string $a_login)