Ejemplo n.º 1
0
 /**
  * Stores the submitted data to the backend / the loginprovider
  *
  * @return string
  */
 protected function actionSaveUser()
 {
     $strReturn = "";
     $bitSelfedit = false;
     $objUsersources = new class_module_user_sourcefactory();
     if ($this->getParam("mode") == "new") {
         if (!$this->getObjModule()->rightEdit()) {
             return $this->getLang("commons_error_permissions");
         }
         $objSubsystem = $objUsersources->getUsersource($this->getParam("usersource"));
         $objBlankUser = $objSubsystem->getNewUser();
         $objForm = $this->getUserForm($objBlankUser, false, "new");
     } else {
         if (!$this->getObjModule()->rightEdit()) {
             if ($this->getSystemid() == $this->objSession->getUserID() && class_module_system_setting::getConfigValue("_user_selfedit_") == "true") {
                 $bitSelfedit = true;
             } else {
                 return $this->getLang("commons_error_permissions");
             }
         }
         $objUser = new class_module_user_user($this->getSystemid());
         $objSourceUser = $objUsersources->getSourceUser($objUser);
         $objForm = $this->getUserForm($objSourceUser, $bitSelfedit, "edit");
     }
     if (($this->getParam("mode") == "new" && !$this->checkAdditionalNewData($objForm)) | ($this->getParam("mode") == "edit" && !$this->checkAdditionalEditData($objForm)) | !$objForm->validateForm()) {
         return $this->actionNewUser($this->getParam("mode"), $objForm);
     }
     $objUser = null;
     if ($this->getParam("mode") == "new") {
         //create a new user and pass all relevant data
         $objUser = new class_module_user_user();
         $objUser->setStrSubsystem($this->getParam("usersource"));
         $objUser->setStrUsername($this->getParam("user_username"));
         $objUser->setIntActive($this->getParam("user_active") != "" && $this->getParam("user_active") == "checked" ? 1 : 0);
         $objUser->setIntAdmin($this->getParam("user_adminlogin") != "" && $this->getParam("user_adminlogin") == "checked" ? 1 : 0);
         $objUser->setIntPortal($this->getParam("user_portal") != "" && $this->getParam("user_portal") == "checked" ? 1 : 0);
     } else {
         if ($this->getParam("mode") == "edit") {
             //create a new user and pass all relevant data
             $objUser = new class_module_user_user($this->getSystemid());
             if (!$bitSelfedit) {
                 $objUser->setStrUsername($this->getParam("user_username"));
                 $objUser->setIntActive($this->getParam("user_active") != "" && $this->getParam("user_active") == "checked" ? 1 : 0);
                 $objUser->setIntAdmin($this->getParam("user_adminlogin") != "" && $this->getParam("user_adminlogin") == "checked" ? 1 : 0);
                 $objUser->setIntPortal($this->getParam("user_portal") != "" && $this->getParam("user_portal") == "checked" ? 1 : 0);
             }
         }
     }
     $objUser->setStrAdminskin($this->getParam("user_skin"));
     $objUser->setStrAdminlanguage($this->getParam("user_language"));
     $objUser->setStrAdminModule($this->getParam("user_startmodule"));
     $objUser->setIntItemsPerPage($this->getParam("user_items_per_page"));
     $objUser->updateObjectToDb();
     $objSourceUser = $objUser->getObjSourceUser();
     $objForm = $this->getUserForm($objSourceUser, $bitSelfedit, $this->getParam("mode"));
     $objForm->updateSourceObject();
     $objSourceUser->updateObjectToDb();
     // assign user to the same groups if we have an user where we inherit the group settings
     if ($this->getParam("mode") == "new") {
         $strInheritUserId = $this->getParam("user_inherit_permissions_id");
         if (!empty($strInheritUserId)) {
             $objInheritUser = new class_module_user_user($strInheritUserId);
             $arrGroupIds = $objInheritUser->getArrGroupIds();
             foreach ($arrGroupIds as $strGroupId) {
                 $objGroup = new class_module_user_group($strGroupId);
                 $objSourceGroup = $objGroup->getObjSourceGroup();
                 $objSourceGroup->addMember($objUser->getObjSourceUser());
             }
             $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul"), "editMemberships", "&systemid=" . $objUser->getStrSystemid()));
             return "";
         }
     }
     if ($this->getParam("mode") == "edit") {
         //Reset the admin-skin cookie to force the new skin
         $objCookie = new class_cookie();
         //flush the db-cache
         class_carrier::getInstance()->getObjDB()->flushQueryCache();
         $this->objSession->resetUser();
         //and update the cookie
         $objCookie->setCookie("adminskin", $this->objSession->getAdminSkin(false, true));
         //update language set before
         $objCookie->setCookie("adminlanguage", $this->objSession->getAdminLanguage(false, true));
     }
     //flush the navigation cache in order to get new items for a possible updated list
     class_admin_helper::flushActionNavigationCache();
     if ($this->getObjModule()->rightView()) {
         $this->adminReload(class_link::getLinkAdminHref($this->getArrModule("modul"), "list"));
     } else {
         $this->adminReload(class_link::getLinkAdminHref($objUser->getStrAdminModule()));
     }
     return $strReturn;
 }
 /**
  * Loads the user identified by the passed name.
  * This method may be called during the authentication of users and may be used as a hook
  * in order to create new users in the central database not yet existing.
  *
  * @param string $strUsername
  *
  * @return interface_usersources_user or null
  */
 public function getUserByUsername($strUsername)
 {
     $strQuery = "SELECT user_id FROM " . _dbprefix_ . "user WHERE user_username = ? AND user_subsystem = 'ldap'";
     $arrIds = class_carrier::getInstance()->getObjDB()->getPRow($strQuery, array($strUsername));
     if (isset($arrIds["user_id"]) && validateSystemid($arrIds["user_id"])) {
         return new class_usersources_user_ldap($arrIds["user_id"]);
     }
     //user not found. search for a matching user in the ldap and add a possible match to the system
     foreach (class_ldap::getAllInstances() as $objSingleLdap) {
         $arrDetails = $objSingleLdap->getUserdetailsByName($strUsername);
         if ($arrDetails !== false && count($arrDetails) == 1) {
             $arrSingleUser = $arrDetails[0];
             $objUser = new class_module_user_user();
             $objUser->setStrUsername($strUsername);
             $objUser->setStrSubsystem("ldap");
             $objUser->setIntActive(1);
             $objUser->setIntAdmin(1);
             $objUser->updateObjectToDb();
             /** @var $objSourceUser class_usersources_user_ldap */
             $objSourceUser = $objUser->getObjSourceUser();
             if ($objSourceUser instanceof class_usersources_user_ldap) {
                 $objSourceUser->setStrDN($arrSingleUser["identifier"]);
                 $objSourceUser->setStrFamilyname($arrSingleUser["familyname"]);
                 $objSourceUser->setStrGivenname($arrSingleUser["givenname"]);
                 $objSourceUser->setStrEmail($arrSingleUser["mail"]);
                 $objSourceUser->setIntCfg($objSingleLdap->getIntCfgNr());
                 $objSourceUser->updateObjectToDb();
                 $this->objDB->flushQueryCache();
                 return $objSourceUser;
             }
         }
     }
     return null;
 }
 /**
  * Returns an array of user-ids associated with the current group.
  * If possible, pageing should be supported
  *
  * @param int $intStart
  * @param int $intEnd
  *
  * @return array
  */
 public function getUserIdsForGroup($intStart = null, $intEnd = null)
 {
     $arrReturn = array();
     //load all members from ldap
     $objLdap = class_ldap::getInstance($this->intCfg);
     $arrMembers = $objLdap->getMembersOfGroup($this->getStrDn());
     $objSource = new class_usersources_source_ldap();
     foreach ($arrMembers as $strOneMemberDn) {
         //check if the user exists in the kajona-database
         $objUser = $objSource->getUserByDn($strOneMemberDn);
         if ($objUser != null) {
             $arrReturn[] = $objUser->getSystemid();
         } else {
             //import the user into the system transparently
             $arrSingleUser = $objLdap->getUserDetailsByDN($strOneMemberDn);
             $objUser = new class_module_user_user();
             $objUser->setStrUsername($arrSingleUser["username"]);
             $objUser->setStrSubsystem("ldap");
             $objUser->setIntActive(1);
             $objUser->setIntAdmin(1);
             $objUser->updateObjectToDb();
             $objSourceUser = $objUser->getObjSourceUser();
             if ($objSourceUser instanceof class_usersources_user_ldap) {
                 $objSourceUser->setStrDN($arrSingleUser["identifier"]);
                 $objSourceUser->setStrFamilyname($arrSingleUser["familyname"]);
                 $objSourceUser->setStrGivenname($arrSingleUser["givenname"]);
                 $objSourceUser->setStrEmail($arrSingleUser["mail"]);
                 $objSourceUser->updateObjectToDb();
                 $this->objDB->flushQueryCache();
             }
             $arrReturn[] = $objUser->getSystemid();
         }
     }
     return $arrReturn;
 }
 /**
  * Creates a form to collect a users data
  *
  * @return string
  */
 private function editUserData()
 {
     $arrErrors = array();
     $bitForm = true;
     //what to do?
     if ($this->getParam("submitUserForm") != "") {
         $objTextValidator = new class_text_validator();
         $objEmailValidator = new class_email_validator();
         if ($this->getParam("password") == "" || $this->getParam("password") != $this->getParam("password2")) {
             $arrErrors[] = $this->getLang("pr_passwordsUnequal");
         }
         if (!$objTextValidator->validate($this->getParam("username"))) {
             $arrErrors[] = $this->getLang("pr_noUsername");
         }
         //username already existing?
         if ($objTextValidator->validate($this->getParam("username")) && count(class_module_user_user::getAllUsersByName($this->getParam("username"))) > 0) {
             $arrErrors[] = $this->getLang("pr_usernameGiven");
         }
         if (!$objEmailValidator->validate($this->getParam("email"))) {
             $arrErrors[] = $this->getLang("pr_invalidEmailadress");
         }
         //Check captachcode
         if ($this->getParam("form_captcha") == "" || $this->getParam("form_captcha") != $this->objSession->getCaptchaCode()) {
             $arrErrors[] = $this->getLang("pr_captcha");
         }
         if (count($arrErrors) == 0) {
             $bitForm = false;
         }
     }
     if ($bitForm) {
         $strTemplateID = $this->objTemplate->readTemplate("/element_portalregistration/" . $this->arrElementData["portalregistration_template"], "portalregistration_userdataform");
         $arrTemplate = array();
         $arrTemplate["username"] = $this->getParam("username");
         $arrTemplate["email"] = $this->getParam("email");
         $arrTemplate["forename"] = $this->getParam("forename");
         $arrTemplate["name"] = $this->getParam("name");
         $arrTemplate["formaction"] = class_link::getLinkPortalHref($this->getPagename(), "", "portalCreateAccount");
         $arrTemplate["formErrors"] = "";
         if (count($arrErrors) > 0) {
             foreach ($arrErrors as $strOneError) {
                 $strErrTemplate = $this->objTemplate->readTemplate("/element_portalregistration/" . $this->arrElementData["portalregistration_template"], "errorRow");
                 $arrTemplate["formErrors"] .= "" . $this->fillTemplate(array("error" => $strOneError), $strErrTemplate);
             }
         }
         return $this->fillTemplate($arrTemplate, $strTemplateID);
     } else {
         //create new user, inactive
         $objUser = new class_module_user_user();
         $objUser->setStrUsername($this->getParam("username"));
         $objUser->setIntActive(0);
         $objUser->setIntAdmin(0);
         $objUser->setIntPortal(1);
         $objUser->setStrSubsystem("kajona");
         $strAuthcode = generateSystemid();
         $objUser->setStrAuthcode($strAuthcode);
         if ($objUser->updateObjectToDb()) {
             $objSourceuser = $objUser->getObjSourceUser();
             $objSourceuser->setStrEmail($this->getParam("email"));
             $objSourceuser->setStrForename($this->getParam("forename"));
             $objSourceuser->setStrName($this->getParam("name"));
             $objSourceuser->setStrPass($this->getParam("password"));
             $objSourceuser->updateObjectToDb();
             //group assignments
             $objGroup = new class_module_user_group($this->arrElementData["portalregistration_group"]);
             $objGroup->getObjSourceGroup()->addMember($objUser->getObjSourceUser());
             //and to the guests to avoid conflicts
             $objGroup = new class_module_user_group(class_module_system_setting::getConfigValue("_guests_group_id_"));
             $objGroup->getObjSourceGroup()->addMember($objUser->getObjSourceUser());
             //create a mail to allow the user to activate itself
             $strMailContent = $this->getLang("pr_email_body");
             $strTemp = getLinkPortalHref($this->getPagename(), "", "portalCompleteRegistration", "&authcode=" . $strAuthcode, $objUser->getSystemid());
             $strMailContent .= html_entity_decode("<a href=\"" . $strTemp . "\">" . $strTemp . "</a>");
             $strMailContent .= $this->getLang("pr_email_footer");
             $objScriptlets = new class_scriptlet_helper();
             $strMailContent = $objScriptlets->processString($strMailContent);
             $objMail = new class_mail();
             $objMail->setSubject($this->getLang("pr_email_subject"));
             $objMail->setHtml($strMailContent);
             $objMail->addTo($this->getParam("email"));
             $objMail->sendMail();
         }
         return $this->getLang("pr_register_suc");
     }
 }