public static function addMember($strFirstname, $strLastname, $strUid, $strEmail, $strUsername, $arrGroups, $strLanguage) { $objMember = new \MemberModel(); // store randomized password, so contao will always trigger the checkCredentials hook $time = time(); $objMember->tstamp = $time; $objMember->dateAdded = $time; $objMember->firstname = $strFirstname; $objMember->lastname = $strLastname; $objMember->ldapUid = $strUid; $objMember->email = $strEmail; $objMember->login = true; $objMember->username = $strUsername; $objMember->password = md5($time . $strUsername); $objMember->groups = serialize($arrGroups); $objMember->language = $strLanguage; $objMember->save(); if (isset($GLOBALS['TL_HOOKS']['ldapAddMember']) && is_array($GLOBALS['TL_HOOKS']['ldapAddMember'])) { foreach ($GLOBALS['TL_HOOKS']['ldapAddMember'] as $callback) { $objMember = call_user_func(array($callback[0], $callback[1]), $objMember); } } $objMember->save(); }
/** * Create a new user and redirect * @param array */ protected function createNewUser($arrData) { $arrData['tstamp'] = time(); $arrData['login'] = $this->reg_allowLogin; $arrData['activation'] = md5(uniqid(mt_rand(), true)); $arrData['dateAdded'] = $arrData['tstamp']; // Set default groups if (!array_key_exists('groups', $arrData)) { $arrData['groups'] = $this->reg_groups; } // Disable account $arrData['disable'] = 1; // Send activation e-mail if ($this->reg_activate) { $arrChunks = array(); $strConfirmation = $this->reg_text; preg_match_all('/##[^#]+##/i', $strConfirmation, $arrChunks); foreach ($arrChunks[0] as $strChunk) { $strKey = substr($strChunk, 2, -2); switch ($strKey) { case 'domain': $strConfirmation = str_replace($strChunk, \Environment::get('host'), $strConfirmation); break; case 'link': $strConfirmation = str_replace($strChunk, \Environment::get('base') . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation'], $strConfirmation); break; // HOOK: support newsletter subscriptions // HOOK: support newsletter subscriptions case 'channel': case 'channels': if (!in_array('newsletter', $this->Config->getActiveModules())) { break; } // Make sure newsletter is an array if (!is_array($arrData['newsletter'])) { if ($arrData['newsletter'] != '') { $arrData['newsletter'] = array($arrData['newsletter']); } else { $arrData['newsletter'] = array(); } } // Replace the wildcard if (!empty($arrData['newsletter'])) { $objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']); if ($objChannels !== null) { $strConfirmation = str_replace($strChunk, implode("\n", $objChannels->fetchEach('title')), $strConfirmation); } } else { $strConfirmation = str_replace($strChunk, '', $strConfirmation); } break; default: $strConfirmation = str_replace($strChunk, $arrData[$strKey], $strConfirmation); break; } } $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Environment::get('host')); $objEmail->text = $strConfirmation; $objEmail->sendTo($arrData['email']); } // Make sure newsletter is an array if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) { $arrData['newsletter'] = array($arrData['newsletter']); } // Create the user $objNewUser = new \MemberModel(); $objNewUser->setRow($arrData); $objNewUser->save(); $insertId = $objNewUser->id; // Assign home directory if ($this->reg_assignDir && is_dir(TL_ROOT . '/' . $this->reg_homeDir)) { $this->import('Files'); $strUserDir = $arrData['username'] ?: 'user_' . $insertId; // Add the user ID if the directory exists if (is_dir(TL_ROOT . '/' . $this->reg_homeDir . '/' . $strUserDir)) { $strUserDir .= '_' . $insertId; } new \Folder($this->reg_homeDir . '/' . $strUserDir); $objNewUser->assignDir = 1; $objNewUser->homeDir = $this->reg_homeDir . '/' . $strUserDir; $objNewUser->save(); } // HOOK: send insert ID and user data if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) { foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($insertId, $arrData, $this); } } // Inform admin if no activation link is sent if (!$this->reg_activate) { $this->sendAdminNotification($insertId, $arrData); } $this->jumpToOrReload($this->objModel->getRelated('jumpTo')->row()); }
/** * Create a new user based on the given data * @param array * @return boolean */ protected function createNewUser($arrProfile) { \System::loadLanguageFile('tl_member'); $this->loadDataContainer('tl_member'); // Call onload_callback (e.g. to check permissions) if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'])) { foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1](); } } } $time = time(); $arrData = array('tstamp' => $time, 'dateAdded' => $time, 'firstname' => $arrProfile['first_name'], 'lastname' => $arrProfile['last_name'], 'gender' => $arrProfile['gender'], 'email' => $arrProfile['email'], 'login' => 1, 'username' => 'fb_' . $arrProfile['id'], 'fblogin' => $arrProfile['id'], 'groups' => $this->reg_groups); $blnHasError = false; // Check the data foreach ($arrData as $k => $v) { if (!isset($GLOBALS['TL_DCA']['tl_member']['fields'][$k])) { unset($arrData[$k]); continue; } $arrField = $GLOBALS['TL_DCA']['tl_member']['fields'][$k]; // Make sure that unique fields are unique if ($arrField['eval']['unique'] && $v != '' && !$this->Database->isUniqueValue('tl_member', $k, $v)) { $blnHasError = true; \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrField['label'][0] ?: $k)); continue; } // Save callback if (is_array($arrField['save_callback'])) { foreach ($arrField['save_callback'] as $callback) { $this->import($callback[0]); try { $v = $this->{$callback}[0]->{$callback}[1]($v, null); } catch (\Exception $e) { $blnHasError = true; \Message::addError($e->getMessage()); } } $arrData[$k] = $v; } } // HOOK: parse data before it is saved if (isset($GLOBALS['TL_HOOKS']['validateFacebookLogin']) && is_array($GLOBALS['TL_HOOKS']['validateFacebookLogin'])) { foreach ($GLOBALS['TL_HOOKS']['validateFacebookLogin'] as $callback) { $this->import($callback[0]); try { $arrData = $this->{$callback}[0]->{$callback}[1]($arrData, $arrProfile); } catch (\Exception $e) { $blnHasError = true; \Message::addError($e->getMessage()); } } } // Return false if there is an error if ($blnHasError) { return false; } $objNewUser = new \MemberModel(); $objNewUser->setRow($arrData); $objNewUser->save(); // Assign home directory if ($this->reg_assignDir) { $objHomeDir = \FilesModel::findByUuid($this->reg_homeDir); if ($objHomeDir !== null) { $this->import('Files'); $strUserDir = standardize($arrData['username']) ?: 'user_' . $objNewUser->id; // Add the user ID if the directory exists while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) { $strUserDir .= '_' . $objNewUser->id; } // Create the user folder new \Folder($objHomeDir->path . '/' . $strUserDir); $objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir); // Save the folder ID $objNewUser->assignDir = 1; $objNewUser->homeDir = $objUserDir->uuid; $objNewUser->save(); } } $insertId = $objNewUser->id; // HOOK: send insert ID and user data if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) { foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($insertId, $arrData, $this, $arrProfile); } } return true; }
/** * Create a new user and redirect * * @param array $arrData */ protected function createNewUser($arrData) { $arrData['tstamp'] = time(); $arrData['login'] = $this->reg_allowLogin; $arrData['activation'] = md5(uniqid(mt_rand(), true)); $arrData['dateAdded'] = $arrData['tstamp']; // Set default groups if (!array_key_exists('groups', $arrData)) { $arrData['groups'] = $this->reg_groups; } // Disable account $arrData['disable'] = 1; // Send activation e-mail if ($this->reg_activate) { // Prepare the simple token data $arrTokenData = $arrData; $arrTokenData['domain'] = \Idna::decode(\Environment::get('host')); $arrTokenData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (\Config::get('disableAlias') || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $arrData['activation']; $arrTokenData['channels'] = ''; if (in_array('newsletter', \ModuleLoader::getActive())) { // Make sure newsletter is an array if (!is_array($arrData['newsletter'])) { if ($arrData['newsletter'] != '') { $arrData['newsletter'] = array($arrData['newsletter']); } else { $arrData['newsletter'] = array(); } } // Replace the wildcard if (!empty($arrData['newsletter'])) { $objChannels = \NewsletterChannelModel::findByIds($arrData['newsletter']); if ($objChannels !== null) { $arrTokenData['channels'] = implode("\n", $objChannels->fetchEach('title')); } } } // Backwards compatibility $arrTokenData['channel'] = $arrTokenData['channels']; $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['emailSubject'], \Idna::decode(\Environment::get('host'))); $objEmail->text = \String::parseSimpleTokens($this->reg_text, $arrTokenData); $objEmail->sendTo($arrData['email']); } // Make sure newsletter is an array if (isset($arrData['newsletter']) && !is_array($arrData['newsletter'])) { $arrData['newsletter'] = array($arrData['newsletter']); } // Create the user $objNewUser = new \MemberModel(); $objNewUser->setRow($arrData); $objNewUser->save(); // Assign home directory if ($this->reg_assignDir) { $objHomeDir = \FilesModel::findByUuid($this->reg_homeDir); if ($objHomeDir !== null) { $this->import('Files'); $strUserDir = standardize($arrData['username']) ?: 'user_' . $objNewUser->id; // Add the user ID if the directory exists while (is_dir(TL_ROOT . '/' . $objHomeDir->path . '/' . $strUserDir)) { $strUserDir .= '_' . $objNewUser->id; } // Create the user folder new \Folder($objHomeDir->path . '/' . $strUserDir); $objUserDir = \FilesModel::findByPath($objHomeDir->path . '/' . $strUserDir); // Save the folder ID $objNewUser->assignDir = 1; $objNewUser->homeDir = $objUserDir->uuid; $objNewUser->save(); } } // HOOK: send insert ID and user data if (isset($GLOBALS['TL_HOOKS']['createNewUser']) && is_array($GLOBALS['TL_HOOKS']['createNewUser'])) { foreach ($GLOBALS['TL_HOOKS']['createNewUser'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objNewUser->id, $arrData, $this); } } // Create the initial version (see #7816) $objVersions = new \Versions('tl_member', $objNewUser->id); $objVersions->setUsername($objNewUser->username); $objVersions->setUserId(0); $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1'); $objVersions->initialize(); // Inform admin if no activation link is sent if (!$this->reg_activate) { $this->sendAdminNotification($objNewUser->id, $arrData); } // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) { $this->jumpToOrReload($objJumpTo->row()); } $this->reload(); }
/** * 更新部门 * * @param array $data * @return boolean */ private function memberUpdate($info) { $model = new MemberModel(); $result = $model->find("UserNo = '" . $info["EmployeeId"] . "'"); if (!$result) { return false; } $data["UserNo"] = $info["EmployeeId"]; $data["UserName"] = $info["Name"]; $data["LoginName"] = $info["LoginName"]; $data["Mobil"] = $info["Mobile"]; $result = $model->save($data, "ID = " . $result["ID"]); return $result; }