示例#1
0
 /**
  * @param int $id
  * @param $email
  * @param $type
  * @param RawData $password
  * @param $status
  * @param $fullname
  * @param $comments
  * @param RawData $currentPassword optional
  * @throws Scalr_Exception_Core
  * @throws Scalr_Exception_InsufficientPermissions
  */
 public function xSaveAction($id = 0, $email, $type, RawData $password, $status, $fullname, $comments, RawData $currentPassword = null)
 {
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     $isNewUser = empty($id);
     $isExistingPasswordChanged = false;
     if (!$isNewUser && $password != '******' && !$this->user->checkPassword($currentPassword)) {
         $this->response->data(['errors' => ['currentPassword' => 'Invalid password']]);
         $this->response->failure();
         return;
     }
     if (!$email) {
         throw new Scalr_Exception_Core('Email cannot be empty');
     }
     if ($type == Scalr_Account_User::TYPE_FIN_ADMIN && $validator->validateEmail($email, null, true) !== true) {
         throw new Scalr_Exception_Core('Email is not valid');
     }
     if (!in_array($type, [Scalr_Account_User::TYPE_SCALR_ADMIN, Scalr_Account_User::TYPE_FIN_ADMIN])) {
         throw new Scalr_Exception_Core('Type is not valid');
     }
     if (!in_array($status, [Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE])) {
         throw new Scalr_Exception_Core('Status is not valid');
     }
     if (!$isNewUser) {
         $user->loadById($id);
         if ($user->getEmail() == 'admin' && $user->getId() != $this->user->getId()) {
             throw new Scalr_Exception_InsufficientPermissions();
         }
         if ($user->getEmail() != 'admin') {
             $user->updateEmail($email);
         }
     } else {
         $user->create($email, $this->user->getAccountId());
         $user->type = $type;
     }
     if ($password != '******') {
         $user->updatePassword($password);
         if (!$isNewUser) {
             $isExistingPasswordChanged = true;
         }
     }
     if ($user->getEmail() != 'admin') {
         $user->status = $status;
         $user->type = $type;
         $user->fullname = $fullname;
         $user->comments = $comments;
     }
     $user->save();
     // Send notification E-mail
     if ($isExistingPasswordChanged) {
         $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/password_change_admin_notification.eml', array('{{fullname}}' => $user->fullname ? $user->fullname : $user->getEmail(), '{{administratorFullName}}' => $this->user->fullname ? $this->user->fullname : $this->user->getEmail()), $user->getEmail(), $user->fullname);
     } else {
         if ($isNewUser) {
             $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/user_new_admin_notification.eml', array('{{fullname}}' => $user->fullname ? $user->fullname : $user->getEmail(), '{{subject}}' => $user->type == Scalr_Account_User::TYPE_FIN_ADMIN ? 'Financial Admin for Scalr Cost Analytics' : 'Admin for Scalr', '{{user_type}}' => $user->type == Scalr_Account_User::TYPE_FIN_ADMIN ? 'a Financial Admin' : 'an Admin', '{{link}}' => Scalr::config('scalr.endpoint.scheme') . "://" . Scalr::config('scalr.endpoint.host')), $user->getEmail(), $user->fullname);
         }
     }
     $this->response->success('User successfully saved');
 }
示例#2
0
文件: Users.php 项目: rickb838/scalr
 /**
  * @param int $id
  * @param $email
  * @param $type
  * @param $password
  * @param $status
  * @param $fullname
  * @param $comments
  * @throws Scalr_Exception_Core
  * @throws Scalr_Exception_InsufficientPermissions
  */
 public function xSaveAction($id = 0, $email, $type, $password, $status, $fullname, $comments)
 {
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     if (!$email) {
         throw new Scalr_Exception_Core('Email cannot be empty');
     }
     if ($type == Scalr_Account_User::TYPE_FIN_ADMIN && $validator->validateEmail($email, null, true) !== true) {
         throw new Scalr_Exception_Core('Email is not valid');
     }
     if (!in_array($type, [Scalr_Account_User::TYPE_SCALR_ADMIN, Scalr_Account_User::TYPE_FIN_ADMIN])) {
         throw new Scalr_Exception_Core('Type is not valid');
     }
     if (!in_array($status, [Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE])) {
         throw new Scalr_Exception_Core('Status is not valid');
     }
     if ($id) {
         $user->loadById($id);
         if ($user->getEmail() == 'admin' && $user->getId() != $this->user->getId()) {
             throw new Scalr_Exception_InsufficientPermissions();
         }
         if ($user->getEmail() != 'admin') {
             $user->updateEmail($email);
         }
     } else {
         $user->create($email, $this->user->getAccountId());
         $user->type = $type;
     }
     if ($password != '******') {
         $user->updatePassword($password);
     }
     if ($user->getEmail() != 'admin') {
         $user->status = $status;
         $user->type = $type;
         $user->fullname = $fullname;
         $user->comments = $comments;
     }
     $user->save();
     $this->response->success('User successfully saved');
 }
示例#3
0
 public function xSaveAction()
 {
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     if (!$this->getParam('email')) {
         throw new Scalr_Exception_Core('Email must be provided.');
     }
     if ($validator->validateEmail($this->getParam('email'), null, true) !== true) {
         throw new Scalr_Exception_Core('Email should be correct');
     }
     if ($this->user->canManageAcl() || $this->user->isTeamOwner()) {
         $newUser = false;
         if ($this->getParam('id')) {
             $user->loadById((int) $this->getParam('id'));
             if (!$this->user->canEditUser($user)) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
             $user->updateEmail($this->getParam('email'));
         } else {
             $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_USERS, 1);
             $user->create($this->getParam('email'), $this->user->getAccountId());
             $user->type = Scalr_Account_User::TYPE_TEAM_USER;
             $newUser = true;
         }
         $sendResetLink = false;
         if (!$this->getParam('password')) {
             $password = CryptoTool::sault(10);
             $sendResetLink = true;
         } else {
             $password = $this->getParam('password');
         }
         if ($password != '******') {
             $user->updatePassword($password);
         }
         if (in_array($this->getParam('status'), array(Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE)) && !$user->isAccountOwner()) {
             $user->status = $this->getParam('status');
         }
         $user->fullname = $this->getParam('fullname');
         $user->comments = $this->getParam('comments');
         $user->save();
         if ($this->getParam('enableApi')) {
             $keys = Scalr::GenerateAPIKeys();
             $user->setSetting(Scalr_Account_User::SETTING_API_ENABLED, true);
             $user->setSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY, $keys['id']);
             $user->setSetting(Scalr_Account_User::SETTING_API_SECRET_KEY, $keys['key']);
         }
         if ($newUser) {
             if ($sendResetLink) {
                 try {
                     $hash = $this->getCrypto()->sault(10);
                     $user->setSetting(Scalr_Account::SETTING_OWNER_PWD_RESET_HASH, $hash);
                     $clientinfo = array('email' => $user->getEmail(), 'fullname' => $user->fullname);
                     // Send reset password E-mail
                     $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/user_account_confirm.eml', array("{{fullname}}" => $clientinfo['fullname'], "{{pwd_link}}" => "https://{$_SERVER['HTTP_HOST']}/#/guest/updatePassword/?hash={$hash}"), $clientinfo['email'], $clientinfo['fullname']);
                 } catch (Exception $e) {
                 }
             }
         }
         $this->response->data(array('user' => array('id' => $user->getId(), 'email' => $user->getEmail(), 'fullname' => $user->fullname)));
         $this->response->success('User successfully saved');
     } else {
         throw new Scalr_Exception_InsufficientPermissions();
     }
 }
示例#4
0
use Scalr\Service\OpenStack\OpenStack;
use Scalr\Service\OpenStack\OpenStackConfig;
use Scalr\Service\OpenStack\Services\Network\Type\CreateSubnet;
use Scalr\Service\OpenStack\Services\Network\Type\CreateRouter;
use Scalr\Modules\Platforms\Openstack\OpenstackPlatformModule;
use Scalr\Service\OpenStack\Services\Servers\Type\ServersExtension;
$validator = new Scalr_Validator();
$crypto = new Scalr_Util_CryptoTool(MCRYPT_TRIPLEDES, MCRYPT_MODE_CFB, 24, 8);
if (!$_REQUEST['update'] && !$_REQUEST['delete']) {
    if (!$_REQUEST['name']) {
        $err['name'] = _("Account name required");
    }
    $name = $_REQUEST['name'];
    $password = $crypto->sault(10);
}
if ($validator->validateEmail($_REQUEST['email'], null, true) !== true) {
    $err['email'] = _("Invalid E-mail address");
}
$email = $_REQUEST['email'];
function getOpenStackOption($name)
{
    return SERVER_PLATFORMS::ECS . "." . constant('Scalr\\Modules\\Platforms\\Openstack\\OpenstackPlatformModule::' . $name);
}
if (count($err) == 0) {
    if ($_REQUEST['delete']) {
        $user = Scalr_Account_User::init()->loadByEmail($email);
        if (!$user) {
            throw new Exception("User Not Found");
        }
        $account = $user->getAccount();
        $account->delete();
示例#5
0
文件: Vhosts.php 项目: mheydt/scalr
 public function xSaveAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_SERVICES_APACHE, Acl::PERM_SERVICES_APACHE_MANAGE);
     $validator = new Scalr_Validator();
     try {
         if ($validator->validateDomain($this->getParam('domainName')) !== true) {
             $err['domainName'] = _("Domain name is incorrect");
         }
         if (!$this->getParam('farmId')) {
             $err['farmId'] = _("Farm required");
         } else {
             $dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
             $this->user->getPermissions()->validate($dbFarm);
         }
         if (!$this->getParam('farmRoleId')) {
             $err['farmRoleId'] = _("Role required");
         } else {
             $dbFarmRole = DBFarmRole::LoadByID($this->getParam('farmRoleId'));
             if ($dbFarmRole->FarmID != $dbFarm->ID) {
                 $err['farmRoleId'] = _("Role not found");
             }
         }
         if ($validator->validateEmail($this->getParam('serverAdmin'), null, true) !== true) {
             $err['serverAdmin'] = _("Server admin's email is incorrect or empty ");
         }
         if (!$this->getParam('documentRoot')) {
             $err['documentRoot'] = _("Document root required");
         }
         if (!$this->getParam('logsDir')) {
             $err['logsDir'] = _("Logs directory required");
         }
         if ($this->db->GetOne("SELECT id FROM apache_vhosts WHERE env_id=? AND `name` = ? AND id != ? AND farm_id = ? AND farm_roleid = ? LIMIT 1", array($this->getEnvironmentId(), $this->getParam('domainName'), $this->getParam('vhostId'), $this->getParam('farmId'), $this->getParam('farmRoleId')))) {
             $err['domainName'] = "'{$this->getParam('domainName')}' virtualhost already exists";
         }
     } catch (Exception $e) {
         $err[] = $e->getMessage();
     }
     if (count($err) == 0) {
         $vHost = Scalr_Service_Apache_Vhost::init();
         if ($this->getParam('vhostId')) {
             $vHost->loadById($this->getParam('vhostId'));
             $this->user->getPermissions()->validate($vHost);
         } else {
             $vHost->envId = $this->getEnvironmentId();
             $vHost->clientId = $this->user->getAccountId();
         }
         $vHost->domainName = $this->getParam('domainName');
         $isSslEnabled = $this->getParam('isSslEnabled') == 'on' ? true : false;
         if ($vHost->farmRoleId && $vHost->farmRoleId != $this->getParam('farmRoleId')) {
             $oldFarmRoleId = $vHost->farmRoleId;
         }
         $vHost->farmId = $this->getParam('farmId');
         $vHost->farmRoleId = $this->getParam('farmRoleId');
         $vHost->isSslEnabled = $isSslEnabled ? 1 : 0;
         $vHost->httpdConf = $this->getParam("nonSslTemplate", true);
         $vHost->templateOptions = serialize(array("document_root" => trim($this->getParam('documentRoot')), "logs_dir" => trim($this->getParam('logsDir')), "server_admin" => trim($this->getParam('serverAdmin')), "server_alias" => trim($this->getParam('serverAlias'))));
         //SSL stuff
         if ($isSslEnabled) {
             $cert = Entity\SslCertificate::findPk($this->getParam('sslCertId'));
             $this->user->getPermissions()->validate($cert);
             $vHost->sslCertId = $cert->id;
             $vHost->httpdConfSsl = $this->getParam("sslTemplate", true);
         } else {
             $vHost->sslCertId = 0;
             $vHost->httpdConfSsl = "";
         }
         $vHost->save();
         $servers = $dbFarm->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
         foreach ($servers as $dBServer) {
             if ($dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::NGINX) || $dBServer->GetFarmRoleObject()->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::APACHE) && $dBServer->farmRoleId == $vHost->farmRoleId) {
                 $dBServer->SendMessage(new Scalr_Messaging_Msg_VhostReconfigure());
             }
         }
         if ($oldFarmRoleId) {
             $oldFarmRole = DBFarmRole::LoadByID($oldFarmRoleId);
             $servers = $oldFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
             foreach ($servers as $dBServer) {
                 $dBServer->SendMessage(new Scalr_Messaging_Msg_VhostReconfigure());
             }
         }
         $this->response->success(_('Virtualhost successfully saved'));
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $err));
     }
 }
示例#6
0
文件: Guest.php 项目: rickb838/scalr
 /**
  * @param string $name
  * @param string $org
  * @param $email
  * @param $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, $password = '', $agreeTerms = '', $newBilling = '', $country = '', $phone = '', $lastname = '', $firstname = '', $v = '', $numServers = '')
 {
     if (!\Scalr::config('scalr.billing.enabled')) {
         exit;
     }
     $Validator = new Scalr_Validator();
     if ($v == 2) {
         if (!$firstname) {
             $err['firstname'] = _("First name required");
         }
         if (!$lastname) {
             $err['lastname'] = _("Last name required");
         }
         //if (!$org)
         //    $err['org'] = _("Organization required");
         $name = $firstname . " " . $lastname;
     } else {
         if (!$name) {
             $err['name'] = _("Account name required");
         }
     }
     if (!$password) {
         $password = $this->getCrypto()->sault(10);
     }
     if ($Validator->validateEmail($email, null, true) !== true) {
         $err['email'] = _("Invalid E-mail address");
     }
     if (strlen($password) < 6) {
         $err['password'] = _("Password should be longer than 6 chars");
     }
     // Check email
     $DBEmailCheck = $this->db->GetOne("SELECT COUNT(*) FROM account_users WHERE email=?", array($email));
     if ($DBEmailCheck > 0) {
         $err['email'] = _("E-mail already exists in database");
     }
     if (!$agreeTerms) {
         $err['agreeTerms'] = _("You need to agree with terms and conditions");
     }
     if (count($err) == 0) {
         $account = Scalr_Account::init();
         $account->name = $org ? $org : $name;
         $account->status = Scalr_Account::STATUS_ACTIVE;
         $account->save();
         $account->createEnvironment("Environment 1");
         $account->initializeAcl();
         $user = $account->createUser($email, $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
         $user->fullname = $name;
         $user->save();
         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;
         }
         $clientSettings[CLIENT_SETTINGS::RSS_LOGIN] = $email;
         $clientSettings[CLIENT_SETTINGS::RSS_PASSWORD] = $this->getCrypto()->sault(10);
         foreach ($clientSettings as $k => $v) {
             $account->setSetting($k, $v);
         }
         try {
             $this->db->Execute("INSERT INTO default_records SELECT null, '{$account->id}', rtype, ttl, rpriority, rvalue, rkey FROM default_records WHERE clientid='0'");
         } 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();
         $this->response->setRedirect("{$url}/thanks.html");
     } else {
         $errors = array_values($err);
         $error = $errors[0];
         $this->response->setRedirect("{$url}/order/?error={$error}");
     }
 }
示例#7
0
 public function xSaveAction()
 {
     $this->request->defineParams(array('teams' => array('type' => 'json'), 'action', 'password' => array('type' => 'string', 'rawValue' => true), 'currentPassword' => array('type' => 'string', 'rawValue' => true)));
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     if ($this->getParam('id')) {
         $user->loadById((int) $this->getParam('id'));
     } else {
         if ($this->getContainer()->config->get('scalr.auth_mode') == 'ldap') {
             throw new Exception("Adding new users is not supported with LDAP user management");
         }
     }
     if ($this->getContainer()->config->get('scalr.auth_mode') != 'ldap') {
         if (!$this->getParam('email')) {
             throw new Scalr_Exception_Core('Email cannot be null');
         }
         if ($validator->validateEmail($this->getParam('email'), null, true) !== true) {
             throw new Scalr_Exception_Core('Email should be correct');
         }
         if ($this->getParam('id')) {
             if (!$this->user->canEditUser($user)) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
             $user->updateEmail($this->getParam('email'));
         } else {
             $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_USERS, 1);
             $user->create($this->getParam('email'), $this->user->getAccountId());
             $user->type = Scalr_Account_User::TYPE_TEAM_USER;
             $newUser = true;
         }
         $password = $this->getParam('password');
         if (!$newUser && $password) {
             $existingPasswordChanged = true;
         } else {
             if (!$password && ($this->request->hasParam('password') || $newUser)) {
                 $password = $this->getCrypto()->sault(10);
                 $sendResetLink = true;
             }
         }
         if (($existingPasswordChanged || !$newUser && $sendResetLink) && !$this->user->checkPassword($this->getParam('currentPassword'))) {
             $this->response->data(['errors' => ['currentPassword' => 'Invalid password']]);
             $this->response->failure();
             return;
         }
         if ($password) {
             $user->updatePassword($password);
         }
     }
     if ($user->getId() != $this->user->getId() && in_array($this->getParam('status'), array(Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE))) {
         $user->status = $this->getParam('status');
     }
     if (!$user->isAccountOwner()) {
         if ($this->getParam('isAccountAdmin')) {
             if ($this->user->isAccountOwner() && $this->getParam('isAccountSuperAdmin')) {
                 $user->type = Scalr_Account_User::TYPE_ACCOUNT_SUPER_ADMIN;
             } else {
                 if ($user->type != Scalr_Account_User::TYPE_ACCOUNT_SUPER_ADMIN) {
                     $user->type = Scalr_Account_User::TYPE_ACCOUNT_ADMIN;
                 }
             }
         } else {
             $user->type = Scalr_Account_User::TYPE_TEAM_USER;
         }
     }
     $user->fullname = $this->getParam('fullname');
     $user->comments = $this->getParam('comments');
     $user->save();
     $user->setAclRoles($this->getParam('teams'));
     if ($this->getParam('enableApi')) {
         $keys = Scalr::GenerateAPIKeys();
         $user->setSetting(Scalr_Account_User::SETTING_API_ENABLED, true);
         $user->setSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY, $keys['id']);
         $user->setSetting(Scalr_Account_User::SETTING_API_SECRET_KEY, $keys['key']);
     }
     $creatorName = $this->user->fullname;
     if (empty($creatorName)) {
         $creatorName = $this->user->isAccountOwner() ? 'Account owner' : ($this->user->isAccountAdmin() ? 'Account admin' : 'Team user');
     }
     if ($newUser) {
         try {
             $clientinfo = array('fullname' => $user->fullname, 'firstname' => $user->fullname, 'email' => $user->getEmail(), 'password' => $password);
             $url = Scalr::config('scalr.endpoint.scheme') . "://" . Scalr::config('scalr.endpoint.host');
             $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/referral.eml.php', array("creatorName" => $creatorName, "clientFirstname" => $clientinfo['firstname'], "email" => $clientinfo['email'], "password" => $clientinfo['password'], "siteUrl" => $url, "wikiUrl" => \Scalr::config('scalr.ui.wiki_url'), "supportUrl" => \Scalr::config('scalr.ui.support_url'), "isUrl" => preg_match('/^http(s?):\\/\\//i', \Scalr::config('scalr.ui.support_url'))), $user->getEmail());
         } catch (Exception $e) {
         }
     } elseif ($sendResetLink) {
         try {
             $hash = $this->getCrypto()->sault(10);
             $user->setSetting(Scalr_Account::SETTING_OWNER_PWD_RESET_HASH, $hash);
             $clientinfo = array('email' => $user->getEmail(), 'fullname' => $user->fullname);
             $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/user_account_confirm.eml', array("{{fullname}}" => $clientinfo['fullname'], "{{pwd_link}}" => "https://{$_SERVER['HTTP_HOST']}/#/guest/updatePassword/?hash={$hash}"), $clientinfo['email'], $clientinfo['fullname']);
         } catch (Exception $e) {
         }
     } else {
         if ($existingPasswordChanged) {
             // Send notification E-mail
             $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/password_change_notification.eml', array('{{fullname}}' => $user->fullname ? $user->fullname : $user->getEmail()), $user->getEmail(), $user->fullname);
         }
     }
     $userTeams = array();
     $troles = $this->getContainer()->acl->getUserRoleIdsByTeam($user->id, array_map(create_function('$v', 'return $v["id"];'), $user->getTeams()), $user->getAccountId());
     foreach ($troles as $teamId => $roles) {
         $userTeams[$teamId] = array('roles' => $roles);
     }
     $data = ['user' => $user->getUserInfo(), 'teams' => $userTeams];
     if ($existingPasswordChanged && $user->getId() == $this->user->getId()) {
         Scalr_Session::create($this->user->getId());
         $data['specialToken'] = Scalr_Session::getInstance()->getToken();
     }
     $this->response->data($data);
     $this->response->success('User successfully saved');
 }
示例#8
0
 public function xSaveSettingsAction()
 {
     $this->request->defineParams(array('dnsZoneId' => array('type' => 'int'), 'axfrAllowedHosts' => array('type' => 'string'), 'allowedAccounts' => array('type' => 'string'), 'allowManageSystemRecords' => array('type' => 'int')));
     $DBDNSZone = DBDNSZone::loadById($this->getParam('dnsZoneId'));
     $this->user->getPermissions()->validate($DBDNSZone);
     $validator = new Scalr_Validator();
     if ($this->getParam('axfrAllowedHosts') != '') {
         $hosts = explode(";", $this->getParam('axfrAllowedHosts'));
         foreach ($hosts as $host) {
             $host = trim($host);
             if ($validator->validateIp($host) !== true) {
                 $errors['axfrAllowedHosts'] = sprintf(_("'%s' is not valid IP address"), $host);
             }
         }
     }
     if ($this->getParam('allowedAccounts')) {
         $accounts = explode(";", $this->getParam('allowedAccounts'));
         foreach ($accounts as $account) {
             if ($validator->validateEmail($account, null, true) !== true) {
                 $errors['allowedAccounts'] = sprintf(_("'%s' is not valid Email address"), $account);
             }
         }
     }
     if (count($errors) == 0) {
         if ($this->getParam('axfrAllowedHosts') != $DBDNSZone->axfrAllowedHosts) {
             $DBDNSZone->axfrAllowedHosts = $this->getParam('axfrAllowedHosts');
             $DBDNSZone->isZoneConfigModified = 1;
         }
         $DBDNSZone->allowManageSystemRecords = $this->getParam('allowManageSystemRecords');
         $DBDNSZone->allowedAccounts = $this->getParam('allowedAccounts');
         $DBDNSZone->save();
         $this->response->success('Changes have been saved. They will become active in few minutes.');
     } else {
         $this->response->failure();
         $this->response->data(array('errors' => $errors));
     }
 }
示例#9
0
文件: Users.php 项目: recipe/scalr
 public function xSaveAction()
 {
     $this->request->defineParams(array('teams' => array('type' => 'json'), 'action'));
     $user = Scalr_Account_User::init();
     $validator = new Scalr_Validator();
     if (!$this->getParam('email')) {
         throw new Scalr_Exception_Core('Email cannot be null');
     }
     if ($validator->validateEmail($this->getParam('email'), null, true) !== true) {
         throw new Scalr_Exception_Core('Email should be correct');
     }
     if ($this->getParam('id')) {
         $user->loadById((int) $this->getParam('id'));
         if (!$this->user->canEditUser($user)) {
             throw new Scalr_Exception_InsufficientPermissions();
         }
         $user->updateEmail($this->getParam('email'));
     } else {
         $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_USERS, 1);
         $user->create($this->getParam('email'), $this->user->getAccountId());
         $user->type = Scalr_Account_User::TYPE_TEAM_USER;
         $newUser = true;
     }
     $password = $this->getParam('password');
     if ($password === '' || $newUser && !$password) {
         $password = $this->getCrypto()->sault(10);
         $sendResetLink = true;
     }
     if ($password) {
         $user->updatePassword($password);
     }
     if ($user->getId() != $this->user->getId() && in_array($this->getParam('status'), array(Scalr_Account_User::STATUS_ACTIVE, Scalr_Account_User::STATUS_INACTIVE))) {
         $user->status = $this->getParam('status');
     }
     if (!$user->isAccountOwner()) {
         $user->type = $this->getParam('isAccountAdmin') ? Scalr_Account_User::TYPE_ACCOUNT_ADMIN : Scalr_Account_User::TYPE_TEAM_USER;
     }
     $user->fullname = $this->getParam('fullname');
     $user->comments = $this->getParam('comments');
     $user->save();
     $user->setAclRoles($this->getParam('teams'));
     if ($this->getParam('enableApi')) {
         $keys = Scalr::GenerateAPIKeys();
         $user->setSetting(Scalr_Account_User::SETTING_API_ENABLED, true);
         $user->setSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY, $keys['id']);
         $user->setSetting(Scalr_Account_User::SETTING_API_SECRET_KEY, $keys['key']);
     }
     $creatorName = $this->user->fullname;
     if (empty($creatorName)) {
         $creatorName = $this->user->isAccountOwner() ? 'Account owner' : ($this->user->isAccountAdmin() ? 'Account admin' : 'Team user');
     }
     if ($newUser) {
         try {
             $clientinfo = array('fullname' => $user->fullname, 'firstname' => $user->fullname, 'email' => $user->getEmail(), 'password' => $password);
             $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/welcome.eml.php', array("creatorName" => $creatorName, "clientFirstname" => $clientinfo['firstname'], "email" => $clientinfo['email'], "password" => $clientinfo['password'], "siteUrl" => "http://{$_SERVER['HTTP_HOST']}", "wikiUrl" => \Scalr::config('scalr.ui.wiki_url'), "supportUrl" => \Scalr::config('scalr.ui.support_url'), "isUrl" => preg_match('/^http(s?):\\/\\//i', \Scalr::config('scalr.ui.support_url'))), $user->getEmail());
         } catch (Exception $e) {
         }
     } elseif ($sendResetLink) {
         try {
             $hash = $this->getCrypto()->sault(10);
             $user->setSetting(Scalr_Account::SETTING_OWNER_PWD_RESET_HASH, $hash);
             $clientinfo = array('email' => $user->getEmail(), 'fullname' => $user->fullname);
             $res = $this->getContainer()->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/user_account_confirm.eml', array("{{fullname}}" => $clientinfo['fullname'], "{{pwd_link}}" => "https://{$_SERVER['HTTP_HOST']}/#/guest/updatePassword/?hash={$hash}"), $clientinfo['email'], $clientinfo['fullname']);
         } catch (Exception $e) {
         }
     }
     $userTeams = array();
     $troles = $this->environment->acl->getUserRoleIdsByTeam($user->id, array_map(create_function('$v', 'return $v["id"];'), $user->getTeams()), $user->getAccountId());
     foreach ($troles as $teamId => $roles) {
         $userTeams[$teamId] = array('roles' => $roles);
     }
     $this->response->data(array('user' => $user->getUserInfo(), 'teams' => $userTeams));
     $this->response->success('User successfully saved');
 }