/** * Used (currently) in the installation script. Note: this function relies on the settings file having * been defined, along with an arbitrary encryption salt. * @param $accountInfo * @param bool $isCurrentUser * @return int */ public static function createAccount($accountInfo, $isCurrentUser = false) { $accountInfo = Utils::sanitize($accountInfo); $encryptionSalt = Core::getEncryptionSalt(); $accountType = $accountInfo["accountType"]; $firstName = isset($accountInfo["firstName"]) && !empty($accountInfo["firstName"]) ? $accountInfo["firstName"] : ""; $lastName = isset($accountInfo["lastName"]) && !empty($accountInfo["lastName"]) ? $accountInfo["lastName"] : ""; $email = isset($accountInfo["email"]) && !empty($accountInfo["email"]) ? $accountInfo["email"] : ""; $password = ""; if (isset($accountInfo["password"]) && !empty($accountInfo["password"])) { $password = crypt($accountInfo["password"], $encryptionSalt); } // TODO - this is weird! $autoEmail = isset($accountInfo["accountType"]) ? $accountInfo["accountType"] : false; $L = Core::$language->getCurrentLanguageStrings(); $now = Utils::getCurrentDatetime(); $prefix = Core::getDbTablePrefix(); $selectedDataTypes = Settings::getSetting("installedDataTypes"); $selectedExportTypes = Settings::getSetting("installedExportTypes"); $selectedCountries = Settings::getSetting("installedCountries"); $result = Core::$db->query("\n\t\t\tINSERT INTO {$prefix}user_accounts (date_created, last_updated, date_expires, last_logged_in, account_type, \n\t\t\t\tfirst_name, last_name, email, password, selected_data_types, selected_export_types, selected_countries)\n\t\t\tVALUES ('{$now}', '{$now}', '{$now}', NULL, '{$accountType}', '{$firstName}', '{$lastName}', '{$email}', '{$password}',\n\t\t\t\t'{$selectedDataTypes}', '\${$selectedExportTypes}', '{$selectedCountries}')\n\t\t"); $emailSent = false; // not used yet, but we should notify the user via the interface if ($autoEmail) { try { $content = $L["account_created_msg"] . "\n\n"; if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"])) { $content .= "{$L["login_url_c"]} {$_SERVER["HTTP_REFERER"]}\n"; } $content .= "{$L["email_c"]} {$email}\n{$L["password_c"]} {$accountInfo["password"]}\n"; Emails::sendEmail(array("recipient" => $email, "subject" => $L["account_created"], "content" => $content)); $emailSent = true; } catch (Exception $e) { $emailSent = false; } } $returnInfo = array("success" => $result["success"]); if ($result["success"]) { $accountID = mysqli_insert_id(Core::$db->getDBLink()); if ($isCurrentUser) { Core::initSessions(); $_SESSION["account_id"] = $accountID; Core::initUser(true); } $returnInfo["accountID"] = $accountID; } return $returnInfo; }
/** * Used (currently) in the installation script. Note: this function relies on the settings file having * been defined, along with an arbitrary encryption salt. * * This is static because it's used during the installation process to create the default account. But in * all other cases its used by the admin only. * * @param array $accountInfo */ public static function createAccount($accountInfo) { $accountInfo = Utils::sanitize($accountInfo); $encryptionSalt = Core::getEncryptionSalt(); $accountType = $accountInfo["accountType"]; $firstName = $accountInfo["firstName"]; $lastName = $accountInfo["lastName"]; $email = $accountInfo["email"]; $password = crypt($accountInfo["password"], $encryptionSalt); $autoEmail = isset($accountInfo["accountType"]) ? $accountInfo["accountType"] : false; $L = Core::$language->getCurrentLanguageStrings(); $now = Utils::getCurrentDatetime(); $prefix = Core::getDbTablePrefix(); $result = Core::$db->query("\n\t\t\tINSERT INTO {$prefix}user_accounts (date_created, last_updated, date_expires, last_logged_in, account_type, \n\t\t\t\tfirst_name, last_name, email, password)\n\t\t\tVALUES ('{$now}', '{$now}', '{$now}', NULL, '{$accountType}', '{$firstName}', '{$lastName}', '{$email}', '{$password}')\n\t\t"); if ($autoEmail) { $content = $L["account_created_msg"] + "\n"; if (isset($_SERVER["HTTP_REFERER"]) && !empty($_SERVER["HTTP_REFERER"])) { $content .= "Login URL: {$_SERVER["HTTP_REFERER"]}\n"; } $content .= "Email: {$email}\nPassword: {$accountInfo["password"]}\n"; $response = Emails::sendEmail(array("recipient" => $email, "subject" => $L["account_created"], "content" => $content)); } // if ($result["success"]) { // $accountID = mysql_insert_id();; // Core::initSessions(); // $_SESSION["account_id"] = $accountID; // Core::initUser(true); // } }