当前位置: 首页>>代码示例>>PHP>>正文


PHP Scalr_Account_User::init方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: getFinancialAdmins

 /**
  * Gets all active financial admins
  *
  * @return   array  Returns all financial admins array(Scalr_Account_User)
  */
 public function getFinancialAdmins()
 {
     $rs = $this->db->Execute("SELECT id FROM account_users WHERE type = ? AND status = ?", [\Scalr_Account_User::TYPE_FIN_ADMIN, \Scalr_Account_User::STATUS_ACTIVE]);
     $result = [];
     while ($row = $rs->FetchRow()) {
         $user = \Scalr_Account_User::init()->loadById($row['id']);
         $result[$user->id] = $user;
     }
     return $result;
 }
开发者ID:rickb838,项目名称:scalr,代码行数:15,代码来源:Notifications.php

示例5: setUser

 /**
  * Sets user which is asssociated with the role superposition object
  *
  * @param   \Scalr_Account_User|int $user User object or ID of the user
  * @return  AccountRoleSuperposition
  * @throws  \InvalidArgumentException
  */
 public function setUser($user)
 {
     if ($user === null || $user instanceof \Scalr_Account_User) {
         $this->user = $user;
     } else {
         $userId = intval($user);
         if (empty($userId)) {
             throw new \InvalidArgumentException("Invalid ID of the user.");
         }
         $this->user = \Scalr_Account_User::init();
         $this->user->loadById($userId);
     }
     return $this;
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:21,代码来源:AccountRoleSuperposition.php

示例6: 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

示例7: 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

示例8: 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

示例9: createUser

 /**
  *
  * @param integer $groupId
  * @param string $login
  * @param string $password
  * @param string $email
  * @return Scalr_Account_User
  */
 public function createUser($email, $password, $type)
 {
     if (!$this->id) {
         throw new Exception("Account is not created");
     }
     $this->validateLimit(Scalr_Limits::ACCOUNT_USERS, 1);
     $user = Scalr_Account_User::init()->create($email, $this->id);
     $user->updatePassword($password);
     $user->type = $type;
     $user->status = Scalr_Account_User::STATUS_ACTIVE;
     $user->save();
     $keys = Scalr::GenerateAPIKeys();
     $user->setSetting(Scalr_Account_User::SETTING_API_ACCESS_KEY, $keys['id']);
     $user->setSetting(Scalr_Account_User::SETTING_API_SECRET_KEY, $keys['key']);
     return $user;
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:24,代码来源:Account.php

示例10: LaunchServer

 /**
  * Launches server
  *
  * @param   \ServerCreateInfo       $ServerCreateInfo optional The server create info
  * @param   \DBServer               $DBServer         optional The DBServer object
  * @param   bool                    $delayed          optional
  * @param   integer|array            $reason           optional
  * @param   \Scalr_Account_User|int $user             optional The Scalr_Account_User object or its unique identifier
  * @return  DBServer|null           Returns the DBServer object on cussess or null otherwise
  */
 public static function LaunchServer(ServerCreateInfo $ServerCreateInfo = null, DBServer $DBServer = null, $delayed = false, $reason = 0, $user = null)
 {
     $db = self::getDb();
     $farm = null;
     //Ensures handling identifier of the user instead of the object
     if ($user !== null && !$user instanceof \Scalr_Account_User) {
         try {
             $user = Scalr_Account_User::init()->loadById(intval($user));
         } catch (\Exception $e) {
         }
     }
     if (!$DBServer && $ServerCreateInfo) {
         $ServerCreateInfo->SetProperties(array(SERVER_PROPERTIES::SZR_KEY => Scalr::GenerateRandomKey(40), SERVER_PROPERTIES::SZR_KEY_TYPE => SZR_KEY_TYPE::ONE_TIME));
         $DBServer = DBServer::Create($ServerCreateInfo, false, true);
     } elseif (!$DBServer && !$ServerCreateInfo) {
         // incorrect arguments
         Logger::getLogger(LOG_CATEGORY::FARM)->error(sprintf("Cannot create server"));
         return null;
     }
     $propsToSet = array();
     if ($user instanceof \Scalr_Account_User) {
         $propsToSet[SERVER_PROPERTIES::LAUNCHED_BY_ID] = $user->id;
         $propsToSet[SERVER_PROPERTIES::LAUNCHED_BY_EMAIL] = $user->getEmail();
     }
     //We should keep role_id and farm_role_id in server properties to use in cost analytics
     if (!empty($DBServer->farmRoleId)) {
         $propsToSet[SERVER_PROPERTIES::FARM_ROLE_ID] = $DBServer->farmRoleId;
         $propsToSet[SERVER_PROPERTIES::ROLE_ID] = $DBServer->farmRoleId ? $DBServer->GetFarmRoleObject()->RoleID : 0;
     }
     try {
         // Ensures the farm object will be fetched as correctly as possible
         $farm = $DBServer->farmId ? $DBServer->GetFarmObject() : null;
         $farmRole = $DBServer->farmRoleId ? $DBServer->GetFarmRoleObject() : null;
         if (!$farmRole instanceof DBFarmRole) {
             $farmRole = null;
         } else {
             if (!$farm instanceof DBFarm) {
                 // Gets farm through FarmRole object in this case
                 $farm = $farmRole->GetFarmObject();
             }
         }
         if ($farm instanceof DBFarm) {
             $propsToSet[SERVER_PROPERTIES::FARM_CREATED_BY_ID] = $farm->createdByUserId;
             $propsToSet[SERVER_PROPERTIES::FARM_CREATED_BY_EMAIL] = $farm->createdByUserEmail;
             $projectId = $farm->GetSetting(DBFarm::SETTING_PROJECT_ID);
             if (!empty($projectId)) {
                 try {
                     $projectEntity = ProjectEntity::findPk($projectId);
                     if ($projectEntity instanceof ProjectEntity) {
                         /* @var $projectEntity ProjectEntity */
                         $ccId = $projectEntity->ccId;
                     } else {
                         $projectId = null;
                     }
                 } catch (Exception $e) {
                     $projectId = null;
                 }
             }
             $propsToSet[SERVER_PROPERTIES::FARM_PROJECT_ID] = $projectId;
         }
         if ($farmRole instanceof DBFarmRole) {
             $propsToSet[SERVER_PROPERTIES::INFO_INSTANCE_TYPE_NAME] = $farmRole->GetSetting(DBFarmRole::SETTING_INFO_INSTANCE_TYPE_NAME);
         }
         if (!empty($ccId)) {
             $propsToSet[SERVER_PROPERTIES::ENV_CC_ID] = $ccId;
         } elseif ($DBServer->envId && ($environment = $DBServer->GetEnvironmentObject()) instanceof Scalr_Environment) {
             $propsToSet[SERVER_PROPERTIES::ENV_CC_ID] = $environment->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
         }
     } catch (Exception $e) {
         Logger::getLogger(LOG_CATEGORY::FARM)->error(sprintf("Could not load related object for recently created server %s. It says: %s", $DBServer->serverId, $e->getMessage()));
     }
     if (!empty($propsToSet)) {
         $DBServer->SetProperties($propsToSet);
     }
     $fnGetReason = function ($reasonId) {
         $args = func_get_args();
         $args[0] = DBServer::getLaunchReason($reasonId);
         return [call_user_func_array('sprintf', $args), $reasonId];
     };
     if ($delayed) {
         $DBServer->status = SERVER_STATUS::PENDING_LAUNCH;
         list($reasonMsg, $reasonId) = is_array($reason) ? call_user_func_array($fnGetReason, $reason) : $fnGetReason($reason);
         $DBServer->SetProperties([SERVER_PROPERTIES::LAUNCH_REASON => $reasonMsg, SERVER_PROPERTIES::LAUNCH_REASON_ID => $reasonId]);
         $DBServer->Save();
         return $DBServer;
     }
     if ($ServerCreateInfo && $ServerCreateInfo->roleId) {
         $dbRole = DBRole::loadById($ServerCreateInfo->roleId);
         if ($dbRole->generation == 1) {
             $DBServer->status = SERVER_STATUS::PENDING_LAUNCH;
//.........这里部分代码省略.........
开发者ID:sacredwebsite,项目名称:scalr,代码行数:101,代码来源:Scalr.php

示例11: dirname

require dirname(__FILE__) . "/../src/prepend.inc.php";
try {
    $dbFarm = DBFarm::LoadByID($_REQUEST['farmid']);
} catch (Exception $e) {
    die("Error (1)");
}
//
// Auth user
//
if (!$_SERVER['PHP_AUTH_USER'] || !$_SERVER['PHP_AUTH_PW']) {
    header('WWW-Authenticate: Basic realm="My Realm"');
    header('HTTP/1.0 401 Unauthorized');
    exit;
} else {
    try {
        $user = Scalr_Account_User::init()->loadBySetting(Scalr_Account_User::SETTING_RSS_LOGIN, $_SERVER['PHP_AUTH_USER']);
    } catch (Exception $e) {
    }
    if (!$user || $_SERVER['PHP_AUTH_PW'] != $user->getSetting(Scalr_Account_User::SETTING_RSS_PASSWORD)) {
        header('WWW-Authenticate: Basic realm="My Realm"');
        header('HTTP/1.0 401 Unauthorized');
        exit;
    }
    if (!$user->getPermissions()->check(Scalr_Environment::init()->loadById($dbFarm->EnvID))) {
        die("Error (2)");
    }
}
header("Content-type: application/rss+xml");
//
// Check cache
//
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:31,代码来源:rss.xml.php

示例12: AuthenticateREST

 private function AuthenticateREST($request)
 {
     if (!$request['Signature']) {
         throw new Exception("Signature is missing");
     }
     if (!$request['KeyID']) {
         throw new Exception("KeyID is missing");
     }
     if (!$request['Timestamp'] && !$request['TimeStamp']) {
         throw new Exception("Timestamp is missing");
     }
     ksort($request);
     $string_to_sign = "";
     foreach ($request as $k => $v) {
         if (!in_array($k, array("Signature"))) {
             if (is_array($v)) {
                 foreach ($v as $kk => $vv) {
                     $string_to_sign .= "{$k}[{$kk}]{$vv}";
                 }
             } else {
                 $string_to_sign .= "{$k}{$v}";
             }
         }
     }
     $this->debug['stringToSign'] = $string_to_sign;
     $this->user = Scalr_Account_User::init()->loadByApiAccessKey($request['KeyID']);
     if (!$this->user) {
         throw new Exception("API Key #{$request['KeyID']} not found in database");
     }
     $auth_key = $this->user->getSetting(Scalr_Account_User::SETTING_API_SECRET_KEY);
     if ($this->user->getAccountId()) {
         if (!$request['EnvID']) {
             $envs = $this->user->getEnvironments();
             if (!$envs[0]['id']) {
                 throw new Exception("User has no access to any environemnts");
             }
             $this->Environment = Scalr_Environment::init()->loadById($envs[0]['id']);
         } else {
             $this->Environment = Scalr_Environment::init()->loadById($request['EnvID']);
         }
         $this->user->getPermissions()->setEnvironmentId($this->Environment->id)->validate($this->Environment);
         //We must set environment to DI Container.
         $this->getContainer()->environment = $this->Environment;
     }
     $valid_sign = base64_encode(hash_hmac(self::HASH_ALGO, trim($string_to_sign), $auth_key, 1));
     if ($valid_sign != $request['Signature']) {
         throw new Exception("Signature doesn't match");
     }
 }
开发者ID:rickb838,项目名称:scalr,代码行数:49,代码来源:class.ScalrAPICore.php

示例13: xRemoveUserAction

 public function xRemoveUserAction()
 {
     $team = $this->getTeam();
     if ($this->user->canManageAcl() || $this->user->isTeamOwner($team->id)) {
         $user = Scalr_Account_User::init();
         $user->loadById($this->getParam('userId'));
         $this->user->getPermissions()->validate($user);
         if (!$this->user->isAccountOwner()) {
             if ($team->isTeamOwner($user->id)) {
                 throw new Scalr_Exception_InsufficientPermissions();
             }
         }
         $team->removeUser($user->id);
         $this->response->success('User has been successfully removed from the team.');
     } else {
         throw new Scalr_Exception_InsufficientPermissions();
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:18,代码来源:Teams.php

示例14: addUser

 public function addUser($userId, $permissions)
 {
     $user = Scalr_Account_User::init();
     $user->loadById($userId);
     if ($user->getAccountId() == $this->accountId) {
         $this->removeUser($userId);
         $this->db->Execute('INSERT INTO `account_team_users` (team_id, user_id, permissions) VALUES(?,?,?)', array($this->id, $userId, $permissions));
     } else {
         throw new Exception('This user doesn\'t belongs to this account');
     }
 }
开发者ID:rakesh-mohanta,项目名称:scalr,代码行数:11,代码来源:Team.php

示例15: xRemoveAction

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


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