protected function __createUser($a_role)
 {
     global $ilSetting, $rbacadmin;
     $this->userObj = new ilObjUser();
     include_once "./Services/User/classes/class.ilUserProfile.php";
     $up = new ilUserProfile();
     $up->setMode(ilUserProfile::MODE_REGISTRATION);
     $map = array();
     $up->skipGroup("preferences");
     $up->skipGroup("settings");
     $up->skipGroup("instant_messengers");
     $up->skipField("password");
     $up->skipField("birthday");
     $up->skipField("upload");
     foreach ($up->getStandardFields() as $k => $v) {
         if ($v["method"]) {
             $method = "set" . substr($v["method"], 3);
             if (method_exists($this->userObj, $method)) {
                 if ($k != "username") {
                     $k = "usr_" . $k;
                 }
                 $field_obj = $this->form->getItemByPostVar($k);
                 if ($field_obj) {
                     $this->userObj->{$method}($this->form->getInput($k));
                 }
             }
         }
     }
     $this->userObj->setFullName();
     $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
     if ($birthday_obj) {
         $birthday = $this->form->getInput("usr_birthday");
         $birthday = $birthday["date"];
         // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui
         if (!is_array($birthday)) {
             $this->userObj->setBirthday($birthday);
         }
     }
     // messenger
     $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip");
     foreach ($map as $client) {
         $field = "usr_im_" . $client;
         $field_obj = $this->form->getItemByPostVar($field);
         if ($field_obj) {
             $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
         }
     }
     $this->userObj->setTitle($this->userObj->getFullname());
     $this->userObj->setDescription($this->userObj->getEmail());
     if ($this->registration_settings->passwordGenerationEnabled()) {
         $password = ilUtil::generatePasswords(1);
         $password = $password[0];
     } else {
         $password = $this->form->getInput("usr_password");
     }
     $this->userObj->setPasswd($password);
     // Set user defined data
     include_once './Services/User/classes/class.ilUserDefinedFields.php';
     $user_defined_fields =& ilUserDefinedFields::_getInstance();
     $defs = $user_defined_fields->getRegistrationDefinitions();
     $udf = array();
     foreach ($_POST as $k => $v) {
         if (substr($k, 0, 4) == "udf_") {
             $f = substr($k, 4);
             $udf[$f] = $v;
         }
     }
     $this->userObj->setUserDefinedData($udf);
     $this->userObj->setTimeLimitOwner(7);
     $this->code_was_used = false;
     if ($this->code_enabled) {
         // #10853 - could be optional
         $code = $this->form->getInput('usr_registration_code');
         if ($code) {
             // set code to used
             include_once './Services/Registration/classes/class.ilRegistrationCode.php';
             ilRegistrationCode::useCode($code);
             $this->code_was_used = true;
         }
     }
     // something went wrong with the form validation
     if (!$a_role) {
         global $ilias;
         $ilias->raiseError("Invalid role selection in registration" . ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
     }
     if ($this->registration_settings->getAccessLimitation()) {
         include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
         $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
         $access_limit_mode = $access_limitations_obj->getMode($a_role);
         if ($access_limit_mode == 'absolute') {
             $access_limit = $access_limitations_obj->getAbsolute($a_role);
             $this->userObj->setTimeLimitUnlimited(0);
             $this->userObj->setTimeLimitUntil($access_limit);
         } elseif ($access_limit_mode == 'relative') {
             $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd');
             $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm');
             $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y');
             $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
             $this->userObj->setTimeLimitUnlimited(0);
             $this->userObj->setTimeLimitUntil($access_limit);
         } else {
             $this->userObj->setTimeLimitUnlimited(1);
             $this->userObj->setTimeLimitUntil(time());
         }
     } else {
         $this->userObj->setTimeLimitUnlimited(1);
         $this->userObj->setTimeLimitUntil(time());
     }
     $this->userObj->setTimeLimitFrom(time());
     $this->userObj->create();
     if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT || $this->registration_settings->getRegistrationType() == IL_REG_CODES || $this->code_was_used) {
         $this->userObj->setActive(1, 0);
     } else {
         if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
             $this->userObj->setActive(0, 0);
         } else {
             $this->userObj->setActive(0, 0);
         }
     }
     $this->userObj->updateOwner();
     // set a timestamp for last_password_change
     // this ts is needed by the ACCOUNT_SECURITY_MODE_CUSTOMIZED
     // in ilSecuritySettings
     $this->userObj->setLastPasswordChangeTS(time());
     //insert user data in table user_data
     $this->userObj->saveAsNew();
     // store acceptance of user agreement
     $this->userObj->writeAccepted();
     // setup user preferences
     $this->userObj->setLanguage($this->form->getInput('usr_language'));
     $hits_per_page = $ilSetting->get("hits_per_page");
     if ($hits_per_page < 10) {
         $hits_per_page = 10;
     }
     $this->userObj->setPref("hits_per_page", $hits_per_page);
     $show_online = $ilSetting->get("show_users_online");
     if ($show_online == "") {
         $show_online = "y";
     }
     $this->userObj->setPref("show_users_online", $show_online);
     $this->userObj->writePrefs();
     $rbacadmin->assignUser((int) $a_role, $this->userObj->getId(), true);
     return $password;
 }
Exemplo n.º 2
0
 public static function useCode($code)
 {
     global $ilDB;
     include_once './Services/Registration/classes/class.ilRegistrationCode.php';
     return (bool) ilRegistrationCode::useCode($code);
     return (bool) $ilDB->update(self::DB_TABLE, array("used" => array("timestamp", time())), array("code" => array("text", $code)));
 }
 protected function __createUser($a_role)
 {
     /**
      * @var $ilSetting ilSetting
      * @var $rbacadmin ilRbacAdmin
      * @var $lng       ilLanguage
      */
     global $ilSetting, $rbacadmin, $lng;
     // something went wrong with the form validation
     if (!$a_role) {
         global $ilias;
         $ilias->raiseError("Invalid role selection in registration" . ", IP: " . $_SERVER["REMOTE_ADDR"], $ilias->error_obj->FATAL);
     }
     $this->userObj = new ilObjUser();
     include_once "./Services/User/classes/class.ilUserProfile.php";
     $up = new ilUserProfile();
     $up->setMode(ilUserProfile::MODE_REGISTRATION);
     $map = array();
     $up->skipGroup("preferences");
     $up->skipGroup("settings");
     $up->skipGroup("instant_messengers");
     $up->skipField("password");
     $up->skipField("birthday");
     $up->skipField("upload");
     foreach ($up->getStandardFields() as $k => $v) {
         if ($v["method"]) {
             $method = "set" . substr($v["method"], 3);
             if (method_exists($this->userObj, $method)) {
                 if ($k != "username") {
                     $k = "usr_" . $k;
                 }
                 $field_obj = $this->form->getItemByPostVar($k);
                 if ($field_obj) {
                     $this->userObj->{$method}($this->form->getInput($k));
                 }
             }
         }
     }
     $this->userObj->setFullName();
     $birthday_obj = $this->form->getItemByPostVar("usr_birthday");
     if ($birthday_obj) {
         $birthday = $this->form->getInput("usr_birthday");
         $birthday = $birthday["date"];
         // when birthday was not set, array will not be substituted with string by ilBirthdayInputGui
         if (!is_array($birthday)) {
             $this->userObj->setBirthday($birthday);
         }
     }
     // messenger
     $map = array("icq", "yahoo", "msn", "aim", "skype", "jabber", "voip");
     foreach ($map as $client) {
         $field = "usr_im_" . $client;
         $field_obj = $this->form->getItemByPostVar($field);
         if ($field_obj) {
             $this->userObj->setInstantMessengerId($client, $this->form->getInput($field));
         }
     }
     $this->userObj->setTitle($this->userObj->getFullname());
     $this->userObj->setDescription($this->userObj->getEmail());
     if ($this->registration_settings->passwordGenerationEnabled()) {
         $password = ilUtil::generatePasswords(1);
         $password = $password[0];
     } else {
         $password = $this->form->getInput("usr_password");
     }
     $this->userObj->setPasswd($password);
     // Set user defined data
     include_once './Services/User/classes/class.ilUserDefinedFields.php';
     $user_defined_fields =& ilUserDefinedFields::_getInstance();
     $defs = $user_defined_fields->getRegistrationDefinitions();
     $udf = array();
     foreach ($_POST as $k => $v) {
         if (substr($k, 0, 4) == "udf_") {
             $f = substr($k, 4);
             $udf[$f] = $v;
         }
     }
     $this->userObj->setUserDefinedData($udf);
     $this->userObj->setTimeLimitOwner(7);
     $access_limit = null;
     $this->code_was_used = false;
     if ($this->code_enabled) {
         $code_local_roles = $code_has_access_limit = null;
         // #10853 - could be optional
         $code = $this->form->getInput('usr_registration_code');
         if ($code) {
             include_once './Services/Registration/classes/class.ilRegistrationCode.php';
             // set code to used
             ilRegistrationCode::useCode($code);
             $this->code_was_used = true;
             // handle code attached local role(s) and access limitation
             $code_data = ilRegistrationCode::getCodeData($code);
             if ($code_data["role_local"]) {
                 // need user id before we can assign role(s)
                 $code_local_roles = explode(";", $code_data["role_local"]);
             }
             if ($code_data["alimit"]) {
                 // see below
                 $code_has_access_limit = true;
                 switch ($code_data["alimit"]) {
                     case "absolute":
                         $abs = date_parse($code_data["alimitdt"]);
                         $access_limit = mktime(23, 59, 59, $abs['month'], $abs['day'], $abs['year']);
                         break;
                     case "relative":
                         $rel = unserialize($code_data["alimitdt"]);
                         $access_limit = $rel["d"] * 86400 + $rel["m"] * 2592000 + $rel["y"] * 31536000 + time();
                         break;
                 }
             }
         }
     }
     // code access limitation will override any other access limitation setting
     if (!($this->code_was_used && $code_has_access_limit) && $this->registration_settings->getAccessLimitation()) {
         include_once 'Services/Registration/classes/class.ilRegistrationRoleAccessLimitations.php';
         $access_limitations_obj = new ilRegistrationRoleAccessLimitations();
         switch ($access_limitations_obj->getMode($a_role)) {
             case 'absolute':
                 $access_limit = $access_limitations_obj->getAbsolute($a_role);
                 break;
             case 'relative':
                 $rel_d = (int) $access_limitations_obj->getRelative($a_role, 'd');
                 $rel_m = (int) $access_limitations_obj->getRelative($a_role, 'm');
                 $rel_y = (int) $access_limitations_obj->getRelative($a_role, 'y');
                 $access_limit = $rel_d * 86400 + $rel_m * 2592000 + $rel_y * 31536000 + time();
                 break;
         }
     }
     if ($access_limit) {
         $this->userObj->setTimeLimitUnlimited(0);
         $this->userObj->setTimeLimitUntil($access_limit);
     } else {
         $this->userObj->setTimeLimitUnlimited(1);
         $this->userObj->setTimeLimitUntil(time());
     }
     $this->userObj->setTimeLimitFrom(time());
     $this->userObj->create();
     if ($this->registration_settings->getRegistrationType() == IL_REG_DIRECT || $this->registration_settings->getRegistrationType() == IL_REG_CODES || $this->code_was_used) {
         $this->userObj->setActive(1, 0);
     } else {
         if ($this->registration_settings->getRegistrationType() == IL_REG_ACTIVATION) {
             $this->userObj->setActive(0, 0);
         } else {
             $this->userObj->setActive(0, 0);
         }
     }
     $this->userObj->updateOwner();
     // set a timestamp for last_password_change
     // this ts is needed by ilSecuritySettings
     $this->userObj->setLastPasswordChangeTS(time());
     $this->userObj->setIsSelfRegistered(true);
     //insert user data in table user_data
     $this->userObj->saveAsNew();
     try {
         require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceSignableDocumentFactory.php';
         ilTermsOfServiceHelper::trackAcceptance($this->userObj, ilTermsOfServiceSignableDocumentFactory::getByLanguageObject($lng));
     } catch (ilTermsOfServiceNoSignableDocumentFoundException $e) {
     }
     // setup user preferences
     $this->userObj->setLanguage($this->form->getInput('usr_language'));
     $hits_per_page = $ilSetting->get("hits_per_page");
     if ($hits_per_page < 10) {
         $hits_per_page = 10;
     }
     $this->userObj->setPref("hits_per_page", $hits_per_page);
     $show_online = $ilSetting->get("show_users_online");
     if ($show_online == "") {
         $show_online = "y";
     }
     $this->userObj->setPref("show_users_online", $show_online);
     $this->userObj->writePrefs();
     $rbacadmin->assignUser((int) $a_role, $this->userObj->getId());
     // local roles from code
     if ($this->code_was_used && is_array($code_local_roles)) {
         foreach (array_unique($code_local_roles) as $local_role_obj_id) {
             // is given role (still) valid?
             if (ilObject::_lookupType($local_role_obj_id) == "role") {
                 $rbacadmin->assignUser($local_role_obj_id, $this->userObj->getId());
             }
         }
     }
     return $password;
 }