Beispiel #1
0
 /**
  * @param string  $name
  * @param string  $org
  * @param string  $email
  * @param RawData $password
  * @param string  $agreeTerms
  * @param string  $newBilling
  * @param string  $country
  * @param string  $phone
  * @param string  $lastname
  * @param string  $firstname
  * @param string  $v
  * @param string  $numServers
  */
 public function xCreateAccountAction($name = '', $org = '', $email = '', RawData $password = null, $agreeTerms = '', $newBilling = '', $country = '', $phone = '', $lastname = '', $firstname = '', $v = '', $numServers = '', $beta = 0)
 {
     if (!\Scalr::config('scalr.billing.enabled')) {
         header("HTTP/1.0 403 Forbidden");
         exit;
     }
     $validator = new Validator();
     if ($v == 2) {
         $validator->validate($firstname, "firstname", Validator::NOEMPTY, [], "First name is required");
         $validator->validate($lastname, "lastname", Validator::NOEMPTY, [], "Last name is required");
         $name = $firstname . " " . $lastname;
     } else {
         $validator->validate($name, "name", Validator::NOEMPTY, [], "Account name is required");
     }
     if ($password == '') {
         $password = \Scalr::GenerateSecurePassword(User::PASSWORD_ADMIN_LENGTH);
     }
     $validator->validate($email, "email", Validator::EMAIL);
     $validator->validate($password, "password", Validator::PASSWORD, ['admin']);
     $validator->addErrorIf($this->db->GetOne("SELECT EXISTS(SELECT * FROM account_users WHERE email = ?)", [$email]), "email", "E-mail already exists in the database");
     $validator->validate($agreeTerms, "agreeTerms", Validator::NOEMPTY, [], "You haven't accepted terms and conditions");
     $errors = $validator->getErrors(true);
     if (empty($errors)) {
         $account = Scalr_Account::init();
         $account->name = $org ? $org : $name;
         $account->status = Scalr_Account::STATUS_ACTIVE;
         $account->save();
         $user = $account->createUser($email, $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
         $user->fullname = $name;
         $user->save();
         if ($this->getContainer()->analytics->enabled) {
             $analytics = $this->getContainer()->analytics;
             //Default Cost Center should be assigned
             $cc = $analytics->ccs->get($analytics->usage->autoCostCentre());
             //Assigns account with Cost Center
             $accountCcEntity = new AccountCostCenterEntity($account->id, $cc->ccId);
             $accountCcEntity->save();
         }
         //Creates Environment. It will be associated with the Cost Center itself.
         $account->createEnvironment("Environment 1");
         $account->initializeAcl();
         if ($v == 2) {
             $user->setSetting('website.phone', $phone);
             $user->setSetting('website.country', $country);
             $user->setSetting('website.num_servers', $numServers);
         }
         /**
          * Limits
          */
         $url = Scalr::config('scalr.endpoint.scheme') . "://" . Scalr::config('scalr.endpoint.host');
         try {
             $billing = new Scalr_Billing();
             $billing->loadByAccount($account);
             $billing->createSubscription(Scalr_Billing::PAY_AS_YOU_GO, "", "", "", "");
         } catch (Exception $e) {
             $account->delete();
             header("Location: {$url}/order/?error={$e->getMessage()}");
             exit;
         }
         if ($_COOKIE['__utmz']) {
             $gaParser = new Scalr_Service_GoogleAnalytics_Parser();
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_CONTENT] = $gaParser->campaignContent;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_MEDIUM] = $gaParser->campaignMedium;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_NAME] = $gaParser->campaignName;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_SOURCE] = $gaParser->campaignSource;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_TERM] = $gaParser->campaignTerm;
             $clientSettings[CLIENT_SETTINGS::GA_FIRST_VISIT] = $gaParser->firstVisit;
             $clientSettings[CLIENT_SETTINGS::GA_PREVIOUS_VISIT] = $gaParser->previousVisit;
             $clientSettings[CLIENT_SETTINGS::GA_TIMES_VISITED] = $gaParser->timesVisited;
         }
         if (!empty($clientSettings)) {
             foreach ($clientSettings as $k => $v) {
                 $account->setSetting($k, $v);
             }
         }
         try {
             $this->db->Execute("\n                    INSERT INTO default_records\n                    SELECT null, '{$account->id}', rtype, ttl, rpriority, rvalue, rkey\n                    FROM default_records\n                    WHERE clientid='0'\n                ");
         } catch (Exception $e) {
         }
         $clientinfo = array('fullname' => $name, 'firstname' => $firstname ? $firstname : $name, 'email' => $email, 'password' => $password);
         //Sends welcome email
         $this->getContainer()->mailer->setFrom('*****@*****.**', 'Scalr')->setHtml()->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/welcome.html.php', array('firstName' => htmlspecialchars($clientinfo['firstname']), 'password' => htmlspecialchars($clientinfo['password']), "siteUrl" => htmlspecialchars($url), "wikiUrl" => htmlspecialchars(\Scalr::config('scalr.ui.wiki_url')), "supportUrl" => htmlspecialchars(\Scalr::config('scalr.ui.support_url')), "isUrl" => preg_match('/^http(s?):\\/\\//i', \Scalr::config('scalr.ui.support_url'))), $email);
         $user->getAccount()->setSetting(Scalr_Account::SETTING_IS_TRIAL, 1);
         //AutoLogin
         $user->updateLastLogin();
         Scalr_Session::create($user->getId());
         Scalr_Session::keepSession();
         if ($beta != 1) {
             $this->response->setRedirect("{$url}/thanks.html");
         } else {
             $this->response->data(array('accountId' => $user->getAccountId()));
         }
     } else {
         if ($beta == 1) {
             header("HTTP/1.0 400 Bad request");
             print json_encode($errors);
             exit;
         } else {
             $error = array_values($errors)[0];
             $this->response->setRedirect("{$url}/order/?error={$error}");
         }
     }
 }