• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Scalr_Account_User类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Scalr_Account_User的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Account_User类的具体用法?PHP Scalr_Account_User怎么用?PHP Scalr_Account_User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Scalr_Account_User类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: handleWork

 function handleWork($farmId)
 {
     try {
         $dbFarm = DBFarm::LoadByID($farmId);
         $governance = new Scalr_Governance($dbFarm->EnvID);
         $settings = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE, 'notifications');
         $curDate = new DateTime();
         $td = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
         if ($td > $curDate) {
             // only inform user
             $days = $td->diff($curDate)->days;
             $notifications = json_decode($dbFarm->GetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND), true);
             if (is_array($settings)) {
                 foreach ($settings as $n) {
                     if (!$notifications[$n['key']] && $n['period'] >= $days) {
                         $mailer = Scalr::getContainer()->mailer;
                         $tdHuman = Scalr_Util_DateTime::convertDateTime($td, $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE), 'M j, Y');
                         if ($n['to'] == 'owner') {
                             $user = new Scalr_Account_User();
                             $user->loadById($dbFarm->createdByUserId);
                             if (Scalr::config('scalr.auth_mode') == 'ldap') {
                                 $email = $user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL);
                                 if (!$email) {
                                     $email = $user->getEmail();
                                 }
                             } else {
                                 $email = $user->getEmail();
                             }
                             $mailer->addTo($email);
                         } else {
                             foreach (explode(',', $n['emails']) as $email) {
                                 $mailer->addTo(trim($email));
                             }
                         }
                         $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_terminate.eml', array('{{terminate_date}}' => $tdHuman, '{{farm}}' => $dbFarm->Name, '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                         $notifications[$n['key']] = 1;
                         $dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, json_encode($notifications));
                         $this->logger->info("Notification was sent by key: " . $n['key'] . " about farm: " . $dbFarm->Name . " by lease manager");
                     }
                 }
             }
         } else {
             // terminate farm
             $event = new FarmTerminatedEvent(0, 1, false, 1);
             Scalr::FireEvent($farmId, $event);
             $this->logger->info("Farm: " . $dbFarm->Name . " was terminated by lease manager");
         }
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:51,代码来源:LeaseManager.php


示例2: getAccountUsersList

 public function getAccountUsersList()
 {
     if ($this->user->canManageAcl()) {
         $result = $this->db->getAll('SELECT account_users.id FROM account_users WHERE account_id = ?', array($this->user->getAccountId()));
         foreach ($result as &$row) {
             $row = Scalr_Account_User::init()->loadById($row['id'])->getUserInfo();
         }
     } else {
         $result = array();
         $teams = $this->user->getTeams();
         if (!empty($teams)) {
             $sql = '
                 SELECT u.id, u.fullname, u.email
                 FROM account_users u
                 INNER JOIN account_team_users tu ON u.id = tu.user_id
                 WHERE account_id= ?';
             $params[] = $this->user->getAccountId();
             foreach ($teams as $team) {
                 $r[] = 'tu.team_id = ?';
                 $params[] = $team['id'];
             }
             $sql .= ' AND (' . implode(' OR ', $r) . ')';
             $result = $this->db->getAll($sql, $params);
         }
     }
     return $result;
 }
开发者ID:scalr,项目名称:scalr,代码行数:27,代码来源:Account2.php


示例3: initializeInstance

 /**
  * @param $type
  * @param $headers
  * @param $server
  * @param $params
  * @param $files
  * @param $userId
  * @param $envId
  * @return Scalr_UI_Request
  * @throws Scalr_Exception_Core
  * @throws Exception
  */
 public static function initializeInstance($type, $headers, $server, $params, $files, $userId, $envId)
 {
     if (self::$_instance) {
         self::$_instance = null;
     }
     $class = get_called_class();
     $instance = new $class($type, $headers, $server, $params, $files);
     if ($userId) {
         try {
             $user = Scalr_Account_User::init();
             $user->loadById($userId);
         } catch (Exception $e) {
             throw new Exception('User account is no longer available.');
         }
         if ($user->status != Scalr_Account_User::STATUS_ACTIVE) {
             throw new Exception('User account has been deactivated. Please contact your account owner.');
         }
         if ($user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             $environment = $user->getDefaultEnvironment($envId);
             $user->getPermissions()->setEnvironmentId($environment->id);
         }
         if ($user->getAccountId()) {
             if ($user->getAccount()->status == Scalr_Account::STATUS_INACIVE) {
                 if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                     throw new Exception('Scalr account has been deactivated. Please contact scalr team.');
                 }
             } else {
                 if ($user->getAccount()->status == Scalr_Account::STATUS_SUSPENDED) {
                     if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                         throw new Exception('Account was suspended. Please contact your account owner to solve this situation.');
                     }
                 }
             }
         }
         $ipWhitelist = $user->getVar(Scalr_Account_User::VAR_SECURITY_IP_WHITELIST);
         if ($ipWhitelist) {
             $ipWhitelist = unserialize($ipWhitelist);
             if (!Scalr_Util_Network::isIpInSubnets($instance->getRemoteAddr(), $ipWhitelist)) {
                 throw new Exception('The IP address isn\'t authorized');
             }
         }
         // check header's variables
         $headerUserId = !is_null($instance->getHeaderVar('UserId')) ? intval($instance->getHeaderVar('UserId')) : null;
         $headerEnvId = !is_null($instance->getHeaderVar('EnvId')) ? intval($instance->getHeaderVar('EnvId')) : null;
         if (!empty($headerUserId) && $headerUserId != $user->getId()) {
             throw new Scalr_Exception_Core('Session expired. Please refresh page.', 1);
         }
         if (!empty($headerEnvId) && !empty($environment) && $headerEnvId != $environment->id) {
             throw new Scalr_Exception_Core('Session expired. Please refresh page.', 1);
         }
         $instance->user = $user;
         $instance->environment = isset($environment) ? $environment : null;
     }
     $container = \Scalr::getContainer();
     $container->request = $instance;
     $container->environment = isset($instance->environment) ? $instance->environment : null;
     self::$_instance = $instance;
     return $instance;
 }
开发者ID:recipe,项目名称:scalr,代码行数:71,代码来源:Request.php


示例4: xRemoveAction

 public function xRemoveAction()
 {
     $user = Scalr_Account_User::init();
     $user->loadById($this->getParam('userId'));
     if ($user->getEmail() == 'admin') {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     $user->delete();
     $this->response->success('User successfully removed');
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:10,代码来源:Users.php


示例5: getUser

 /**
  * Gets an test User instance
  *
  * @return  \Scalr_Account_user Returns user instance
  */
 protected function getUser()
 {
     if (!isset($this->user)) {
         if (empty($this->_testUserId)) {
             $this->_testUserId = \Scalr::config('scalr.phpunit.userid');
         }
         $this->user = \Scalr_Account_User::init();
         $this->user->loadById($this->_testUserId);
     }
     return $this->user;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:16,代码来源:WebTestCase.php


示例6: getUserInfoByAccountId

 protected function getUserInfoByAccountId($accountId)
 {
     if (!isset($this->accountsCache[$accountId])) {
         if ($accountId) {
             try {
                 $acc = new \Scalr_Account();
                 $acc->loadById($accountId);
                 $this->accountsCache[$accountId] = array('id' => $acc->getOwner()->id, 'email' => $acc->getOwner()->getEmail());
             } catch (\Exception $e) {
                 $this->console->error($e->getMessage());
                 return array('id' => 0, 'email' => '');
             }
         } else {
             $user = new \Scalr_Account_User();
             $user->loadByEmail('admin', 0);
             $this->accountsCache[$accountId] = array('id' => $user->id, 'email' => $user->getEmail());
         }
     }
     return $this->accountsCache[$accountId];
 }
开发者ID:mheydt,项目名称:scalr,代码行数:20,代码来源:Update20140204143602.php


示例7: callActionMethod

 public function callActionMethod($method)
 {
     if ($this->request->getRequestType() == Scalr_UI_Request::REQUEST_TYPE_API) {
         $apiMethodCheck = false;
         if (method_exists($this, 'getApiDefinitions')) {
             $api = $this::getApiDefinitions();
             $m = str_replace('Action', '', $method);
             if (in_array($m, $api)) {
                 $apiMethodCheck = true;
             }
         }
         if (!$apiMethodCheck) {
             throw new Scalr_UI_Exception_NotFound();
         }
     }
     if ($this->user) {
         if ($this->user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
             if (!$this->user->isTeamUserInEnvironment($this->getEnvironmentId(), Scalr_Account_Team::PERMISSIONS_OWNER) && !$this->user->isTeamUserInEnvironment($this->getEnvironmentId(), Scalr_Account_Team::PERMISSIONS_FULL)) {
                 if (method_exists($this, 'getPermissionDefinitions')) {
                     // rules defined for this controller
                     $cls = get_class($this);
                     $clsShort = str_replace('Scalr_UI_Controller_', '', $cls);
                     $methodShort = str_replace('Action', '', $method);
                     $clsPermissions = $cls::getPermissionDefinitions();
                     $permissions = $this->user->getGroupPermissions($this->getEnvironmentId());
                     if (array_key_exists($clsShort, $permissions)) {
                         // rules for user and such controller
                         $perm = $permissions[$clsShort];
                         if (!in_array('FULL', $perm, true)) {
                             // user doesn't has full privilegies
                             if (array_key_exists($methodShort, $clsPermissions)) {
                                 // standalone rule for this method
                                 if (!in_array($clsPermissions[$methodShort], $perm)) {
                                     throw new Scalr_Exception_InsufficientPermissions();
                                 }
                             } else {
                                 // VIEW rule
                                 if (!in_array('VIEW', $perm)) {
                                     throw new Scalr_Exception_InsufficientPermissions();
                                 }
                             }
                         }
                     } else {
                         throw new Scalr_Exception_InsufficientPermissions();
                     }
                 }
             }
         }
     }
     $this->{$method}();
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:51,代码来源:Controller.php


示例8: xRequestResultAction

 public function xRequestResultAction()
 {
     $this->request->defineParams(array('requests' => array('type' => 'json'), 'decision'));
     if (!in_array($this->getParam('decision'), array(FarmLease::STATUS_APPROVE, FarmLease::STATUS_DECLINE))) {
         throw new Scalr_Exception_Core('Wrong status');
     }
     foreach ($this->getParam('requests') as $id) {
         $req = $this->db->GetRow('SELECT * FROM farm_lease_requests WHERE id = ? LIMIT 1', array($id));
         if ($req) {
             $dbFarm = DBFarm::LoadByID($req['farm_id']);
             $this->user->getPermissions()->validate($dbFarm);
             $this->db->Execute('UPDATE farm_lease_requests SET status = ?, answer_comment = ?, answer_user_id = ? WHERE id = ?', array($this->getParam('decision'), $this->getParam('comment'), $this->user->getId(), $id));
             try {
                 $mailer = Scalr::getContainer()->mailer;
                 $user = new Scalr_Account_User();
                 $user->loadById($dbFarm->createdByUserId);
                 if ($this->getContainer()->config('scalr.auth_mode') == 'ldap') {
                     if ($user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL)) {
                         $mailer->addTo($user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL));
                     } else {
                         $mailer->addTo($user->getEmail());
                     }
                 } else {
                     $mailer->addTo($user->getEmail());
                 }
             } catch (Exception $e) {
                 $mailer = null;
             }
             if ($this->getParam('decision') == FarmLease::STATUS_APPROVE) {
                 if ($req['request_days'] > 0) {
                     $dt = $dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE);
                     $dt = new DateTime($dt);
                     $dt->add(new DateInterval('P' . $req['request_days'] . 'D'));
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, null);
                     if ($mailer) {
                         $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_approve.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{date}}' => $dt->format('M j, Y'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                     }
                 } else {
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, '');
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, '');
                     $dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, '');
                     if ($mailer) {
                         $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_forever.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                     }
                 }
             } else {
                 $dt = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
                 SettingEntity::increase(SettingEntity::LEASE_DECLINED_REQUEST);
                 if ($mailer) {
                     $mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_non_standard_decline.eml', array('{{farm_name}}' => $dbFarm->Name, '{{user_name}}' => $this->user->getEmail(), '{{date}}' => $dt->format('M j, Y'), '{{comment}}' => $this->getParam('comment'), '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
                 }
             }
         }
     }
     $this->response->success();
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:57,代码来源:Lease.php


示例9: run1

 /**
  * Performs upgrade literally for the stage ONE.
  *
  * Implementation of this method performs update steps needs to be taken
  * to accomplish upgrade successfully.
  *
  * If there are any error during an execution of this scenario it must
  * throw an exception.
  *
  * @param   int  $stage  optional The stage number
  * @throws  \Exception
  */
 protected function run1($stage)
 {
     $dashboards = $this->db->Execute('SELECT user_id, env_id FROM account_user_dashboard');
     foreach ($dashboards as $keys) {
         try {
             $user = new \Scalr_Account_User();
             $user->loadById($keys['user_id']);
             $dash = $user->getDashboard($keys['env_id']);
             if (!(is_array($dash) && isset($dash['configuration']) && is_array($dash['configuration']) && isset($dash['flags']) && is_array($dash['flags']))) {
                 // old configuration, remove it
                 $this->db->Execute('DELETE FROM account_user_dashboard WHERE user_id = ? AND env_id = ?', array($keys['user_id'], $keys['env_id']));
                 continue;
             }
             foreach ($dash['configuration'] as &$column) {
                 foreach ($column as &$widget) {
                     if ($widget['name'] == 'dashboard.monitoring') {
                         $metrics = array('CPUSNMP' => 'cpu', 'LASNMP' => 'la', 'NETSNMP' => 'net', 'ServersNum' => 'snum', 'MEMSNMP' => 'mem');
                         $params = array('farmId' => $widget['params']['farmid'], 'period' => $widget['params']['graph_type'], 'metrics' => $metrics[$widget['params']['watchername']], 'title' => $widget['params']['title'], 'hash' => $this->db->GetOne('SELECT hash FROM farms WHERE id = ?', array($widget['params']['farmid'])));
                         if (stristr($widget['params']['role'], "INSTANCE_")) {
                             $ar = explode('_', $widget['params']['role']);
                             $params['farmRoleId'] = $ar[1];
                             $params['index'] = $ar[2];
                         } else {
                             if ($widget['params']['role'] != 'FARM' && $widget['params']['role'] != 'role') {
                                 $params['farmRoleId'] = $widget['params']['role'];
                             }
                         }
                         $widget['params'] = $params;
                     }
                 }
             }
             $user->setDashboard($keys['env_id'], $dash);
         } catch (\Exception $e) {
             $this->console->warning($e->getMessage());
         }
     }
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:49,代码来源:Update20140306123554.php


示例10: run1

 protected function run1($stage)
 {
     $this->db->Execute('
         ALTER TABLE `timeline_events`
             ADD `account_id` int(11) NULL AFTER `user_id`,
             ADD `env_id` int(11) NULL AFTER `account_id`,
             ADD INDEX `idx_account_id` (`account_id` ASC),
             ADD INDEX `idx_env_id` (`env_id` ASC)
     ');
     $res = $this->db->Execute('SELECT * FROM timeline_events');
     while ($item = $res->FetchRow()) {
         $event = new TimelineEventEntity();
         $event->load($item);
         try {
             $event->accountId = \Scalr_Account_User::init()->loadById($event->userId)->getAccountId();
         } catch (Exception $e) {
             continue;
         }
         $event->save();
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:21,代码来源:Update20141002103526.php


示例11: onCloudAdd

 /**
  * Raises onCloudAdd notification event
  *
  * @param   string              $platform    A platform name.
  * @param   \Scalr_Environment  $environment An environment object which cloud is created in.
  * @param   \Scalr_Account_User $user        An user who has created platform.
  */
 public function onCloudAdd($platform, $environment, $user)
 {
     $container = \Scalr::getContainer();
     $analytics = $container->analytics;
     //Nothing to do in case analytics is disabled
     if (!$analytics->enabled) {
         return;
     }
     if (!$environment instanceof \Scalr_Environment) {
         $environment = \Scalr_Environment::init()->loadById($environment);
     }
     $pm = PlatformFactory::NewPlatform($platform);
     //Check if there are some price for this platform and endpoint url
     if (($endpointUrl = $pm->hasCloudPrices($environment)) === true) {
         return;
     }
     //Disabled or badly configured environment
     if ($endpointUrl === false && !in_array($platform, [\SERVER_PLATFORMS::EC2, \SERVER_PLATFORMS::GCE])) {
         return;
     }
     //Send a message to financial admin if there are not any price for this cloud
     $baseUrl = rtrim($container->config('scalr.endpoint.scheme') . "://" . $container->config('scalr.endpoint.host'), '/');
     //Disable notifications for hosted Scalr
     if (!\Scalr::isAllowedAnalyticsOnHostedScalrAccount($environment->clientId)) {
         return;
     }
     $emails = $this->getFinancialAdminEmails();
     //There isn't any financial admin
     if (empty($emails)) {
         return;
     }
     $emails = array_map(function ($email) {
         return '<' . trim($email, '<>') . '>';
     }, $emails);
     try {
         $res = $container->mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/analytics_on_cloud_add.eml.php', ['isPublicCloud' => $platform == \SERVER_PLATFORMS::EC2, 'userEmail' => $user->getEmail(), 'cloudName' => \SERVER_PLATFORMS::GetName($platform), 'linkToPricing' => $baseUrl . '/#/analytics/pricing?platform=' . urlencode($platform) . '&url=' . urlencode($endpointUrl === false ? '' : $analytics->prices->normalizeUrl($endpointUrl))], join(',', $emails));
     } catch (\Exception $e) {
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:46,代码来源:Notifications.php


示例12: FarmGetDetails

 public function FarmGetDetails($FarmID)
 {
     $response = parent::FarmGetDetails($FarmID);
     try {
         $DBFarm = DBFarm::LoadByID($FarmID);
         if ($DBFarm->EnvID != $this->Environment->id) {
             throw new Exception("N");
         }
     } catch (Exception $e) {
         throw new Exception(sprintf("Farm #%s not found", $FarmID));
     }
     $response->ID = $DBFarm->ID;
     $response->Name = $DBFarm->Name;
     $response->IsLocked = $DBFarm->GetSetting(DBFarm::SETTING_LOCK);
     if ($response->IsLocked == 1) {
         $response->LockComment = $DBFarm->GetSetting(DBFarm::SETTING_LOCK_COMMENT);
         try {
             $response->LockedBy = Scalr_Account_User::init()->loadById($DBFarm->GetSetting(DBFarm::SETTING_LOCK_BY))->fullname;
         } catch (Exception $e) {
         }
     }
     foreach ($response->FarmRoleSet->Item as &$item) {
         $dbFarmRole = DBFarmRole::LoadByID($item->ID);
         $item->IsScalingEnabled = $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_ENABLED);
         $item->{"ScalingAlgorithmSet"} = new stdClass();
         $item->{"ScalingAlgorithmSet"}->Item = array();
         $metrics = $this->DB->GetAll("SELECT metric_id, name, dtlastpolled FROM `farm_role_scaling_metrics`\n                    INNER JOIN scaling_metrics ON scaling_metrics.id = farm_role_scaling_metrics.metric_id WHERE farm_roleid = ?", array($item->ID));
         foreach ($metrics as $metric) {
             $itm = new stdClass();
             $itm->MetricID = $metric['id'];
             $itm->MetricName = $metric['name'];
             $itm->DateLastPolled = $metric['dtlastpolled'];
             $item->{"ScalingAlgorithmSet"}->Item[] = $itm;
         }
     }
     return $response;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:37,代码来源:class.ScalrAPI_2_3_0.php


示例13: initializeInstance

 public static function initializeInstance($type, $userId, $envId)
 {
     $instance = new Scalr_UI_Request($type);
     if ($userId) {
         try {
             $user = Scalr_Account_User::init();
             $user->loadById($userId);
         } catch (Exception $e) {
             throw new Exception('User account is no longer available.');
         }
         if ($user->status != Scalr_Account_User::STATUS_ACTIVE) {
             throw new Exception('User account has been deactivated. Please contact your account owner.');
         }
         if ($user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             $environment = $user->getDefaultEnvironment($envId);
             $user->getPermissions()->setEnvironmentId($environment->id);
         }
         if ($user->getAccountId()) {
             if ($user->getAccount()->status == Scalr_Account::STATUS_INACIVE) {
                 if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                     throw new Exception('Scalr account has been deactivated. Please contact scalr team.');
                 }
             } else {
                 if ($user->getAccount()->status == Scalr_Account::STATUS_SUSPENDED) {
                     if ($user->getType() == Scalr_Account_User::TYPE_TEAM_USER) {
                         throw new Exception('Account was suspended. Please contact your account owner to solve this situation.');
                     }
                 }
             }
         }
         $instance->user = $user;
         $instance->environment = $environment;
     }
     self::$_instance = $instance;
     return $instance;
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:36,代码来源:Request.php


示例14: canEditUser

 /**
  * Checks whether the user is allowed to edit specified user
  *
  * @param   \Scalr_Account_User  $user The user to edit
  * @return  boolean              Returns true if the user is allowed to edit specified user
  */
 public function canEditUser($user)
 {
     return !$this->isTeamUser() && $user->getAccountId() == $this->getAccountId() && ($this->getId() == $user->getId() || $this->isAccountOwner() || $this->isAccountSuperAdmin() && !$user->isAccountOwner() || $this->isAccountAdmin() && !$user->isAccountOwner() && !$user->isAccountSuperAdmin());
 }
开发者ID:rickb838,项目名称:scalr,代码行数:10,代码来源:User.php


示例15: migrateEc2Location

 /**
  * Migrates an Image to another Cloud Location
  *
  * @param  string $cloudLocation The cloud location
  * @param  \Scalr_Account_User|\Scalr\Model\Entity\Account\User $user The user object
  * @return Image
  * @throws Exception
  * @throws NotEnabledPlatformException
  * @throws DomainException
  */
 public function migrateEc2Location($cloudLocation, $user)
 {
     if (!$this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2)) {
         throw new NotEnabledPlatformException("You can migrate image between regions only on EC2 cloud");
     }
     if ($this->cloudLocation == $cloudLocation) {
         throw new DomainException('Destination region is the same as source one');
     }
     $snap = $this->getEnvironment()->aws($this->cloudLocation)->ec2->image->describe($this->id);
     if ($snap->count() == 0) {
         throw new Exception("Image haven't been found on cloud.");
     }
     if ($snap->get(0)->toArray()['imageState'] != 'available') {
         throw new Exception('Image is not in "available" status on cloud and cannot be copied.');
     }
     $this->checkImage();
     // re-check properties
     $aws = $this->getEnvironment()->aws($cloudLocation);
     $newImageId = $aws->ec2->image->copy($this->cloudLocation, $this->id, $this->name, "Image was copied by Scalr from image: {$this->name}, cloudLocation: {$this->cloudLocation}, id: {$this->id}", null, $cloudLocation);
     $newImage = new Image();
     $newImage->platform = $this->platform;
     $newImage->cloudLocation = $cloudLocation;
     $newImage->id = $newImageId;
     $newImage->name = $this->name;
     $newImage->architecture = $this->architecture;
     $newImage->size = $this->size;
     $newImage->accountId = $this->accountId;
     $newImage->envId = $this->envId;
     $newImage->osId = $this->osId;
     $newImage->source = Image::SOURCE_MANUAL;
     $newImage->type = $this->type;
     $newImage->agentVersion = $this->agentVersion;
     $newImage->createdById = $user->getId();
     $newImage->createdByEmail = $user->getEmail();
     $newImage->status = Image::STATUS_ACTIVE;
     $newImage->isScalarized = $this->isScalarized;
     $newImage->hasCloudInit = $this->hasCloudInit;
     $newImage->save();
     $newImage->setSoftware($this->getSoftware());
     return $newImage;
 }
开发者ID:scalr,项目名称:scalr,代码行数:51,代码来源:Image.php


示例16: xRemoveAction

 public function xRemoveAction()
 {
     $user = Scalr_Account_User::init();
     $user->loadById($this->getParam('userId'));
     if ($user->getAccountId() == $this->user->getAccountId()) {
         if ($this->user->canManageAcl() || $this->user->isTeamOwner()) {
             $user->delete();
             $this->response->success('User has been successfully removed.');
             return;
         }
     }
     throw new Scalr_Exception_InsufficientPermissions();
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:13,代码来源:Users.php


示例17: foreach

     $envId = $env->id;
     $user = $account->createUser($email, $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
     $user->fullname = $name;
     $user->save();
     $clientSettings[CLIENT_SETTINGS::RSS_LOGIN] = $email;
     $clientSettings[CLIENT_SETTINGS::RSS_PASSWORD] = $crypto->sault(10);
     foreach ($clientSettings as $k => $v) {
         $account->setSetting($k, $v);
     }
     try {
         $db->Execute("INSERT INTO default_records SELECT null, '{$account->id}', type, ttl, priority, value, name FROM default_records WHERE clientid='0'");
     } catch (Exception $e) {
         $err['db'] = $e->getMessage();
     }
 } else {
     $user = Scalr_Account_User::init()->loadByEmail($email);
     if (!$user) {
         throw new Exception("User Not Found");
     }
     $account = $user->getAccount();
     $env = $user->getDefaultEnvironment();
     $envId = $env->id;
 }
 try {
     $retval = array('success' => true, 'account' => array('id' => $account->id, 'userId' => $user->id, 'password' => $password, 'envId' => $env->id, 'api_access_key' => $user->getSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY), 'api_secret_key' => $user->getSetting(Scalr_Account_User::SETTING_API_SECRET_KEY)));
     $updateEnv = false;
     if (!$_REQUEST['update']) {
         //CONFIGURE OPENSTACK:
         $pars[SERVER_PLATFORMS::ECS . "." . OpenstackPlatformModule::KEYSTONE_URL] = $_REQUEST['openstack_keystone_url'];
         $pars[SERVER_PLATFORMS::ECS . "." . OpenstackPlatformModule::USERNAME] = $_REQUEST['openstack_username'];
         $pars[SERVER_PLATFORMS::ECS . "." . OpenstackPlatformModule::PASSWORD] = $_REQUEST['openstack_password'];
开发者ID:rickb838,项目名称:scalr,代码行数:31,代码来源:manager.php


示例18: isLocked

 /**
  * Check if farm is locked
  *
  * @param  $throwException
  * @return bool
  * @throws Exception
  */
 public function isLocked($throwException = true)
 {
     if ($this->GetSetting(Entity\FarmSetting::LOCK)) {
         $message = $this->GetSetting(Entity\FarmSetting::LOCK_COMMENT);
         try {
             $userName = Scalr_Account_User::init()->loadById($this->getSetting(Entity\FarmSetting::LOCK_BY))->getEmail();
         } catch (Exception $e) {
             $userName = $this->getSetting(Entity\FarmSetting::LOCK_BY);
         }
         if ($message) {
             $message = sprintf(' with comment: \'%s\'', $message);
         }
         if ($throwException) {
             throw new Exception(sprintf('Farm was locked by %s%s. Please unlock it first.', $userName, $message));
         } else {
             return sprintf('Farm was locked by %s%s.', $userName, $message);
         }
     }
     return false;
 }
开发者ID:scalr,项目名称:scalr,代码行数:27,代码来源:class.DBFarm.php


示例19: checkPermission

 /**
  * @param \Scalr_Account_User $user
  * @param int $envId
  * @throws \Scalr_Exception_InsufficientPermissions
  */
 public function checkPermission(\Scalr_Account_User $user, $envId)
 {
     if ($this->accountId && $this->accountId != $user->getAccountId()) {
         throw new \Scalr_Exception_InsufficientPermissions();
     }
     if ($this->envId && $this->envId != $envId) {
         throw new \Scalr_Exception_InsufficientPermissions();
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:14,代码来源:Script.php


示例20: isUserAllowedByEnvironment

 /**
  * Checks wheter access to ACL resource or unique permission is allowed.
  *
  * @param   \Scalr_Account_User $user                  The user
  * @param   \Scalr_Environment  $environment           The client's environment
  * @param   int                 $resourceId            The ID of the ACL resource or its symbolic name without "RESOURCE_" prefix.
  * @param   string              $permissionId optional The ID of the uniqure permission which is
  *                                            related to specified resource.
  * @return  bool                Returns TRUE if access is allowed
  */
 public function isUserAllowedByEnvironment(\Scalr_Account_User $user, $environment, $resourceId, $permissionId = null)
 {
     //Checks wheter environment and user are from the same account.
     if ($user->isScalrAdmin()) {
         return true;
     } else {
         if (!$environment instanceof \Scalr_Environment) {
             //If environment is not defined it will return false.
             return false;
         } else {
             if ($environment->clientId != $user->getAccountId()) {
                 return false;
             }
         }
     }
     //Scalr-Admin and Account-Owner is allowed for everything
     if ($user->isAccountOwner()) {
         return true;
     }
     if (is_string($resourceId)) {
         $sName = 'Scalr\\Acl\\Acl::RESOURCE_' . strtoupper($resourceId);
         if (defined($sName)) {
             $resourceId = constant($sName);
         } else {
             throw new \InvalidArgumentException(sprintf('Cannot find ACL resource %s by specified symbolic name %s.', $sName, $resourceId));
         }
     }
     return (bool) $user->getAclRolesByEnvironment($environment->id)->isAllowed($resourceId, $permissionId);
 }
开发者ID:recipe,项目名称:scalr,代码行数:39,代码来源:Acl.php



注:本文中的Scalr_Account_User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Scalr_Environment类代码示例发布时间:2022-05-23
下一篇:
PHP Scalr类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap