/** * 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) { $this->sendActivationMail($arrData); } // 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 = \StringUtil::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')) instanceof PageModel) { $this->jumpToOrReload($objJumpTo->row()); } $this->reload(); }
/** * Imports a user from phpbb to contao * * @param $username * @param $password * @return bool * @throws \Exception */ public function importUser($username, $password) { if ($this->debug) { System::log("phpbb_bridge: " . __METHOD__, __METHOD__, TL_ACCESS); } // Find User in forum $user = $this->getUser($username); if ($user) { System::log('Importing User ' . $username, __METHOD__, TL_ACCESS); // Try to find user by real username if he entered username_clean // he may not be imported yet with it's clean username $contaoUser = MemberModel::findByUsername($user->username); if (null == $contaoUser) { $contaoUser = new MemberModel(); } $contaoUser->username = $user->username; $contaoUser->username_clean = $user->username_clean; $contaoUser->email = $user->user_email; $contaoUser->firstname = 'Vorname'; $contaoUser->lastname = 'Nachname'; $contaoUser->password = Encryption::hash($password); $contaoUser->login = 1; $contaoUser->tstamp = $contaoUser->dateAdded = time(); $contaoUser->groups = $this->getForumMemberGroupIds(true); // @todo add try catch, make it more safe, logout phpbb user on fail? $contaoUser->save(); System::log('User imported: ' . $contaoUser->username, __METHOD__, TL_ACCESS); // username_clean used for login if ($username != $contaoUser->username) { Input::setPost('username', $contaoUser->username); } return true; } else { System::log($username . ' could not be found in phpbb db', __METHOD__, TL_ACCESS); return false; } }