362 : string
363 {
364
365 if (!$a_role) {
367
368 $ilias =
$DIC[
'ilias'];
369 $ilias->raiseError(
370 'Invalid role selection in registration' .
372 $ilias->error_obj->FATAL
373 );
374 }
375
378 $this->userObj->setAuthMode('local');
379 }
380
381 $this->userObj = $this->user_profile->addFormValuesToUser(
383 Context::Registration,
384 $this->userObj
385 );
386 $this->userObj->setTitle($this->userObj->getFullname());
387 $this->userObj->setDescription($this->userObj->getEmail());
388
389 $this->userObj->setLogin(
390 $this->
form->getInput(
'username')
391 );
392
393 if ($this->registration_settings->passwordGenerationEnabled()) {
395 $password = $password[0];
396 } else {
397 $password = $this->
form->getInput(
'password');
398 }
399
400 $this->userObj->setLanguage(
401 $this->user_settings->getValueFromLegacyFormByDefinitionClass(
402 LanguageSetting::class,
403 $this->form
404 )
405 );
406
407 $this->userObj->setPasswd($password);
408
409 $access_limit = null;
410
411 $this->code_was_used = false;
412 $code_has_access_limit = false;
413 $code_local_roles = [];
414 if ($this->code_enabled) {
415 $code_local_roles = $code_has_access_limit = null;
416
417
418 $code = $this->
form->getInput(
'usr_registration_code');
419 if ($code) {
420
422 $this->code_was_used = true;
423
424
426 if ($code_data['role_local']) {
427
428 $code_local_roles = explode(';', $code_data['role_local']);
429 }
430 if ($code_data['alimit']) {
431
432 $code_has_access_limit = true;
433
434 switch ($code_data['alimit']) {
435 case 'absolute':
436 $abs = date_parse($code_data['alimitdt']);
437 $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
438 break;
439
440 case 'relative':
441 $rel = unserialize($code_data['alimitdt'], ['allowed_classes' => false]);
442 $access_limit = (
int) ($rel[
'd'] * 86400 + $rel[
'm'] * 2592000 + $rel[
'y'] * 31536000 + time());
443 break;
444 }
445 }
446 }
447 }
448
449
450 if (!($this->code_was_used && $code_has_access_limit) &&
451 $this->registration_settings->getAccessLimitation()) {
453 switch ($access_limitations_obj->getMode($a_role)) {
454 case 'absolute':
455 $access_limit = $access_limitations_obj->getAbsolute($a_role);
456 break;
457
458 case 'relative':
459 $rel_d = $access_limitations_obj->getRelative($a_role, 'd');
460 $rel_m = $access_limitations_obj->getRelative($a_role, 'm');
461 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + time();
462 break;
463 }
464 }
465
466 if ($access_limit) {
467 $this->userObj->setTimeLimitUnlimited(false);
468 $this->userObj->setTimeLimitUntil($access_limit);
469 } else {
470 $this->userObj->setTimeLimitUnlimited(true);
471 $this->userObj->setTimeLimitUntil(time());
472 }
473
474 $this->userObj->setTimeLimitFrom(time());
475
477
478 $this->userObj->create();
479
482 $this->code_was_used) {
483 $this->userObj->setActive(true, 0);
485 $this->userObj->setActive(false, 0);
486 } else {
487 $this->userObj->setActive(false, 0);
488 }
489
490
491
492 $this->userObj->setLastPasswordChangeTS(time());
493
494 $this->userObj->setIsSelfRegistered(true);
495
496
497 $this->userObj->saveAsNew();
498
499
500 $this->userObj->updateOwner();
501
502
503 $this->userObj->setLanguage($this->
form->getInput(
'usr_language'));
504
506 $DIC[
'legalDocuments']->selfRegistration()->userCreation($this->userObj);
507
508 if ($this->
http->wrapper()->query()->has(
'target')) {
509 $this->userObj->setPref(
510 'reg_target',
511 $this->
http->wrapper()->query()->retrieve(
512 'target',
513 $this->refinery->kindlyTo()->string()
514 )
515 );
516 }
517 $this->userObj->setPref(
'bs_allow_to_contact_me', $this->
settings->get(
'bs_allow_to_contact_me',
'n'));
518 $this->userObj->setPref(
'chat_osc_accept_msg', $this->
settings->get(
'chat_osc_accept_msg',
'n'));
519 $this->userObj->setPref(
'chat_broadcast_typing', $this->
settings->get(
'chat_broadcast_typing',
'n'));
520 $this->userObj->writePrefs();
521
522 $this->rbacadmin->assignUser($a_role, $this->userObj->getId());
523
524
525 if ($this->code_was_used && is_array($code_local_roles)) {
526 $code_local_roles = array_map(intval(...), array_unique($code_local_roles));
527 foreach ($code_local_roles as $local_role_obj_id) {
528
530 $this->rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
531
532
533 $role_obj =
$GLOBALS[
'DIC'][
'rbacreview']->getObjectOfRole($local_role_obj_id);
535 case 'crs':
536 case 'grp':
538 $role_ref = end($role_refs);
539
540
541
542 break;
543 }
544 }
545 }
546 }
547
548 return (string) $password;
549 }
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static useCode(string $code)
static getCodeData(string $code)
Class class.ilRegistrationAccessLimitation.
static generatePasswords(int $a_number)
Generate a number of passwords.
const CONTEXT_REGISTRATION