本文整理汇总了PHP中Scalr_Account_User::loadById方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Account_User::loadById方法的具体用法?PHP Scalr_Account_User::loadById怎么用?PHP Scalr_Account_User::loadById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Account_User
的用法示例。
在下文中一共展示了Scalr_Account_User::loadById方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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;
}
示例4: 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());
}
}
示例5: 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());
}
}
}
示例6: xLoginAsAction
public function xLoginAsAction()
{
if ($this->getParam('accountId')) {
$account = new Scalr_Account();
$account->loadById($this->getParam('accountId'));
$user = $account->getOwner();
} else {
$user = new Scalr_Account_User();
$user->loadById($this->getParam('userId'));
}
if ($user->status != User::STATUS_ACTIVE) {
throw new Exception('User account has been deactivated. You cannot login into it.');
}
Scalr_Session::create($user->getId(), $this->user->getId());
try {
$envId = $this->getEnvironmentId(true) ?: $user->getDefaultEnvironment()->id;
} catch (Exception $e) {
$envId = null;
}
$this->auditLog("user.auth.login", $user, $envId, $this->request->getRemoteAddr(), $this->user->getId());
$this->response->success();
}
示例7: xLoginAsAction
public function xLoginAsAction()
{
if ($this->getParam('accountId')) {
$account = new Scalr_Account();
$account->loadById($this->getParam('accountId'));
$user = $account->getOwner();
} else {
$user = new Scalr_Account_User();
$user->loadById($this->getParam('userId'));
}
Scalr_Session::create($user->getId(), true);
$this->response->success();
}
示例8: loginUserGet
//.........这里部分代码省略.........
$this->response->data(array('accounts' => $userAvailableAccounts));
throw new Exception();
}
}
$user = new Scalr_Account_User();
$user = $user->loadByEmail($login, $accountId);
if (!$user) {
$user = new Scalr_Account_User();
$user->type = Scalr_Account_User::TYPE_TEAM_USER;
$user->status = Scalr_Account_User::STATUS_ACTIVE;
$user->create($login, $accountId);
}
if (!$user->fullname) {
$user->fullname = $ldap->getFullName();
$user->save();
}
if ($ldap->getUsername() != $ldap->getEmail()) {
$user->setSetting(Scalr_Account_User::SETTING_LDAP_EMAIL, $ldap->getEmail());
} else {
$user->setSetting(Scalr_Account_User::SETTING_LDAP_EMAIL, '');
}
} else {
throw new Exception("Incorrect login or password (1) " . $ldap->getLog());
}
} else {
$userAvailableAccounts = $this->db->GetAll('
SELECT account_users.id AS userId, clients.id, clients.name, clients.org, clients.dtadded, au.email AS `owner`
FROM account_users
LEFT JOIN clients ON clients.id = account_users.account_id
LEFT JOIN account_users au ON account_users.account_id = au.account_id
WHERE account_users.email = ? AND (au.type = ? OR account_users.type = ? OR account_users.type = ?)
GROUP BY userId
', array($login, Scalr_Account_User::TYPE_ACCOUNT_OWNER, Scalr_Account_User::TYPE_SCALR_ADMIN, Scalr_Account_User::TYPE_FIN_ADMIN));
foreach ($userAvailableAccounts as &$ac) {
$ac['dtadded'] = Scalr_Util_DateTime::convertTz($ac['dtadded'], 'M j, Y');
}
if (count($userAvailableAccounts) == 1) {
$user = new Scalr_Account_User();
$user->loadById($userAvailableAccounts[0]['userId']);
} else {
if (count($userAvailableAccounts) > 1) {
if ($accountId) {
foreach ($userAvailableAccounts as $acc) {
if ($acc['id'] == $accountId) {
$user = new Scalr_Account_User();
$user->loadById($acc['userId']);
break;
}
}
} else {
$this->response->data(array('accounts' => $userAvailableAccounts));
throw new Exception();
}
} else {
throw new Exception("Incorrect login or password (3)");
}
}
if ($user) {
// kaptcha
if ($user->loginattempts > 2 && $this->getContainer()->config->get('scalr.ui.recaptcha.private_key')) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.google.com/recaptcha/api/verify');
curl_setopt($curl, CURLOPT_POST, true);
$post = 'privatekey=' . urlencode($this->getContainer()->config->get('scalr.ui.recaptcha.private_key')) . '&remoteip=' . urlencode($this->request->getRemoteAddr()) . '&challenge=' . urlencode($scalrCaptchaChallenge) . '&response=' . urlencode($scalrCaptcha);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
$response = curl_exec($curl);
curl_close($curl);
$responseStrings = explode("\n", $response);
if ($responseStrings[0] !== 'true') {
$this->response->data(array('loginattempts' => $user->loginattempts, 'kaptchaError' => $response));
throw new Exception();
}
}
if (!$user->checkPassword($password)) {
if ($this->getContainer()->config->get('scalr.ui.recaptcha.private_key')) {
$this->response->data(array('loginattempts' => $user->loginattempts));
}
throw new Exception("Incorrect login or password (1)");
}
} else {
throw new Exception("Incorrect login or password (2)");
}
}
// valid user, other checks
$whitelist = $user->getVar(Scalr_Account_User::VAR_SECURITY_IP_WHITELIST);
if ($whitelist) {
$subnets = unserialize($whitelist);
if (!Scalr_Util_Network::isIpInSubnets($this->request->getRemoteAddr(), $subnets)) {
throw new Exception('The IP address you are attempting to log in from isn\'t authorized');
}
}
return $user;
} else {
throw new Exception('Incorrect login or password (0)');
}
}
示例9: xBuildAction
public function xBuildAction()
{
$this->request->defineParams(array('farmId' => array('type' => 'int'), 'roles' => array('type' => 'json'), 'farm' => array('type' => 'json'), 'roleUpdate' => array('type' => 'int'), 'launch' => array('type' => 'bool')));
if (!$this->isFarmConfigurationValid($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'))) {
if ($this->errors['error_count'] != 0) {
$this->response->failure();
$this->response->data(array('errors' => $this->errors));
return;
}
}
$farm = $this->getParam('farm');
$client = Client::Load($this->user->getAccountId());
if ($this->getParam('farmId')) {
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
$this->request->restrictFarmAccess($dbFarm, Acl::PERM_FARMS_MANAGE);
$dbFarm->isLocked();
if ($this->getParam('changed') && $dbFarm->changedTime && $this->getParam('changed') != $dbFarm->changedTime) {
$userName = 'Someone';
$changed = explode(' ', $this->getParam('changed'));
$changedTime = intval($changed[1]);
try {
$user = new Scalr_Account_User();
$user->loadById($dbFarm->changedByUserId);
$userName = $user->getEmail();
} catch (Exception $e) {
}
$this->response->failure();
$this->response->data(array('changedFailure' => sprintf('%s changed this farm at %s', $userName, Scalr_Util_DateTime::convertTz($changedTime))));
return;
}
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
$bNew = false;
} else {
$this->request->restrictFarmAccess(null, Acl::PERM_FARMS_MANAGE);
$this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_FARMS, 1);
$dbFarm = new DBFarm();
$dbFarm->ClientID = $this->user->getAccountId();
$dbFarm->EnvID = $this->getEnvironmentId();
$dbFarm->Status = FARM_STATUS::TERMINATED;
$dbFarm->createdByUserId = $this->user->getId();
$dbFarm->createdByUserEmail = $this->user->getEmail();
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
$bNew = true;
}
if ($this->getParam('farm')) {
$dbFarm->Name = $this->request->stripValue($farm['name']);
$dbFarm->RolesLaunchOrder = $farm['rolesLaunchOrder'];
$dbFarm->Comments = $this->request->stripValue($farm['description']);
}
if (empty($dbFarm->Name)) {
throw new Exception(_("Farm name required"));
}
if ($bNew) {
$dbFarm->teamId = is_numeric($farm['teamOwner']) && $farm['teamOwner'] > 0 ? $farm['teamOwner'] : NULL;
} else {
if ($dbFarm->createdByUserId == $this->user->getId() || $this->user->isAccountOwner() || $this->request->isFarmAllowed($dbFarm, Acl::PERM_FARMS_CHANGE_OWNERSHIP)) {
if (is_numeric($farm['owner']) && $farm['owner'] != $dbFarm->createdByUserId) {
$user = (new Scalr_Account_User())->loadById($farm['owner']);
$dbFarm->createdByUserId = $user->getId();
$dbFarm->createdByUserEmail = $user->getEmail();
// TODO: move to subclass \Farm\Setting\OwnerHistory
$history = unserialize($dbFarm->GetSetting(DBFarm::SETTING_OWNER_HISTORY));
if (!is_array($history)) {
$history = [];
}
$history[] = ['newId' => $user->getId(), 'newEmail' => $user->getEmail(), 'changedById' => $this->user->getId(), 'changedByEmail' => $this->user->getEmail(), 'dt' => date('Y-m-d H:i:s')];
$dbFarm->SetSetting(DBFarm::SETTING_OWNER_HISTORY, serialize($history));
}
$dbFarm->teamId = is_numeric($farm['teamOwner']) && $farm['teamOwner'] > 0 ? $farm['teamOwner'] : NULL;
}
}
$dbFarm->save();
$governance = new Scalr_Governance($this->getEnvironmentId());
if (!$this->getParam('farmId') && $governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE)) {
$dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
// for created farm
}
if (isset($farm['variables'])) {
$variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
$variables->setValues(is_array($farm['variables']) ? $farm['variables'] : [], 0, $dbFarm->ID, 0, '', false, true);
}
if (!$farm['timezone']) {
$farm['timezone'] = date_default_timezone_get();
}
$dbFarm->SetSetting(DBFarm::SETTING_TIMEZONE, $farm['timezone']);
$dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_ID, $farm['vpc_id']);
$dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_REGION, $farm['vpc_region']);
$dbFarm->SetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY, $farm[DBFarm::SETTING_SZR_UPD_REPOSITORY]);
$dbFarm->SetSetting(DBFarm::SETTING_SZR_UPD_SCHEDULE, $farm[DBFarm::SETTING_SZR_UPD_SCHEDULE]);
if (!$dbFarm->GetSetting(DBFarm::SETTING_CRYPTO_KEY)) {
$dbFarm->SetSetting(DBFarm::SETTING_CRYPTO_KEY, Scalr::GenerateRandomKey(40));
}
if ($this->getContainer()->analytics->enabled) {
//Cost analytics project must be set for the Farm object
$dbFarm->setProject(!empty($farm['projectId']) ? $farm['projectId'] : null);
}
$virtualFarmRoles = array();
//.........这里部分代码省略.........
示例10: loginUserGet
//.........这里部分代码省略.........
$ids[] = $value['id'];
}
if (!$accountId && !in_array($accountId, $ids)) {
$this->response->data(array('accounts' => $userAvailableAccounts));
throw new Exception();
}
}
$user = new Scalr_Account_User();
$user = $user->loadByEmail($login, $accountId);
if (!$user) {
$user = new Scalr_Account_User();
$user->type = Scalr_Account_User::TYPE_TEAM_USER;
$user->status = Scalr_Account_User::STATUS_ACTIVE;
$user->create($login, $accountId);
}
if (!$user->fullname) {
$user->fullname = $ldap->getFullName();
$user->save();
}
if ($ldap->getUsername() != $ldap->getEmail()) {
$user->setSetting(Scalr_Account_User::SETTING_LDAP_EMAIL, $ldap->getEmail());
$user->setSetting(Scalr_Account_User::SETTING_LDAP_USERNAME, $ldap->getUsername());
} else {
$user->setSetting(Scalr_Account_User::SETTING_LDAP_EMAIL, '');
}
} else {
throw new Exception("Incorrect login or password (1) " . $ldap->getLog());
}
} else {
$userAvailableAccounts = $this->db->GetAll('
SELECT account_users.id AS userId, clients.id, clients.name, clients.org, clients.dtadded, au.email AS `owner`
FROM account_users
LEFT JOIN clients ON clients.id = account_users.account_id
LEFT JOIN account_users au ON account_users.account_id = au.account_id
WHERE account_users.email = ? AND (au.type = ? OR account_users.type = ? OR account_users.type = ?)
GROUP BY userId
', array($login, Scalr_Account_User::TYPE_ACCOUNT_OWNER, Scalr_Account_User::TYPE_SCALR_ADMIN, Scalr_Account_User::TYPE_FIN_ADMIN));
foreach ($userAvailableAccounts as &$ac) {
$ac['dtadded'] = Scalr_Util_DateTime::convertTz($ac['dtadded'], 'M j, Y');
}
if (count($userAvailableAccounts) == 1) {
$user = new Scalr_Account_User();
$user->loadById($userAvailableAccounts[0]['userId']);
} elseif (count($userAvailableAccounts) > 1) {
if ($accountId) {
foreach ($userAvailableAccounts as $acc) {
if ($acc['id'] == $accountId) {
$user = new Scalr_Account_User();
$user->loadById($acc['userId']);
break;
}
}
} else {
$this->response->data(array('accounts' => $userAvailableAccounts));
throw new Exception();
}
} else {
throw new Exception("Incorrect login or password (3)");
}
if ($user) {
if ($user->status != User::STATUS_ACTIVE) {
throw new Exception('User account has been deactivated. Please contact your account owner.');
}
// kaptcha
if ($user->loginattempts > 3 && $this->getContainer()->config->get('scalr.ui.recaptcha.private_key')) {
if (!$scalrCaptcha || ($r = $this->validateReCaptcha($scalrCaptcha)) !== true) {
$this->response->data(array('loginattempts' => $user->loginattempts, 'scalrCaptchaError' => isset($r) ? $r : 'empty-value'));
throw new Exception();
}
}
if (!$user->checkPassword($password)) {
$attempts = (int) $this->getContainer()->config->get('scalr.security.user.suspension.failed_login_attempts');
if ($attempts > 0 && $user->loginattempts >= $attempts && $user->getEmail() != 'admin') {
$user->status = User::STATUS_INACTIVE;
$user->loginattempts = 0;
$user->save();
throw new Exception('User account has been deactivated. Please contact your account owner.');
}
if ($this->getContainer()->config->get('scalr.ui.recaptcha.private_key')) {
$this->response->data(array('loginattempts' => $user->loginattempts));
}
throw new Exception("Incorrect login or password (1)");
}
} else {
throw new Exception("Incorrect login or password (2)");
}
}
// valid user, other checks
$whitelist = $user->getVar(Scalr_Account_User::VAR_SECURITY_IP_WHITELIST);
if ($whitelist) {
$subnets = unserialize($whitelist);
if (!Scalr_Util_Network::isIpInSubnets($this->request->getRemoteAddr(), $subnets)) {
throw new Exception('The IP address you are attempting to log in from isn\'t authorized');
}
}
return $user;
} else {
throw new Exception('Incorrect login or password (0)');
}
}
示例11: xBuildAction
public function xBuildAction()
{
$this->request->defineParams(array('farmId' => array('type' => 'int'), 'roles' => array('type' => 'json'), 'farm' => array('type' => 'json'), 'roleUpdate' => array('type' => 'int')));
$this->request->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE);
if (!$this->isFarmConfigurationValid($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'))) {
if ($this->errors['error_count'] != 0) {
$this->response->failure();
$this->response->data(array('errors' => $this->errors));
return;
}
}
$farm = $this->getParam('farm');
$client = Client::Load($this->user->getAccountId());
if ($this->getParam('farmId')) {
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
$dbFarm->isLocked();
if ($this->getParam('changed') && $dbFarm->changedTime && $this->getParam('changed') != $dbFarm->changedTime) {
$userName = 'Someone';
$changed = explode(' ', $this->getParam('changed'));
$changedTime = intval($changed[1]);
try {
$user = new Scalr_Account_User();
$user->loadById($dbFarm->changedByUserId);
$userName = $user->getEmail();
} catch (Exception $e) {
}
$this->response->failure();
$this->response->data(array('changedFailure' => sprintf('%s changed this farm at %s', $userName, Scalr_Util_DateTime::convertTz($changedTime))));
return;
}
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
} else {
$this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_FARMS, 1);
$dbFarm = new DBFarm();
$dbFarm->Status = FARM_STATUS::TERMINATED;
$dbFarm->createdByUserId = $this->user->getId();
$dbFarm->createdByUserEmail = $this->user->getEmail();
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
}
if ($this->getParam('farm')) {
$dbFarm->Name = strip_tags($farm['name']);
$dbFarm->RolesLaunchOrder = $farm['rolesLaunchOrder'];
$dbFarm->Comments = trim(strip_tags($farm['description']));
}
if (empty($dbFarm->Name)) {
throw new Exception(_("Farm name required"));
}
$dbFarm->save();
$governance = new Scalr_Governance($this->getEnvironmentId());
if ($governance->isEnabled(Scalr_Governance::GENERAL_LEASE)) {
$dbFarm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
}
if (isset($farm['variables'])) {
$variables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
$variables->setValues($farm['variables'], 0, $dbFarm->ID, 0, '', false);
}
if (!$farm['timezone']) {
$farm['timezone'] = date_default_timezone_get();
}
$dbFarm->SetSetting(DBFarm::SETTING_TIMEZONE, $farm['timezone']);
$dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_ID, $farm['vpc_id']);
$dbFarm->SetSetting(DBFarm::SETTING_EC2_VPC_REGION, $farm['vpc_region']);
if (!$dbFarm->GetSetting(DBFarm::SETTING_CRYPTO_KEY)) {
$dbFarm->SetSetting(DBFarm::SETTING_CRYPTO_KEY, Scalr::GenerateRandomKey(40));
}
$virtualFarmRoles = array();
$roles = $this->getParam('roles');
if (!empty($roles)) {
foreach ($roles as $role) {
if (strpos($role['farm_role_id'], "virtual_") !== false) {
$dbRole = DBRole::loadById($role['role_id']);
$dbFarmRole = $dbFarm->AddRole($dbRole, $role['platform'], $role['cloud_location'], (int) $role['launch_index'], $role['alias']);
$virtualFarmRoles[$role['farm_role_id']] = $dbFarmRole->ID;
}
}
}
$usedPlatforms = array();
$dbFarmRolesList = array();
$newFarmRolesList = array();
$farmRoleVariables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
if (!empty($roles)) {
foreach ($roles as $role) {
if ($role['farm_role_id']) {
if ($virtualFarmRoles[$role['farm_role_id']]) {
$role['farm_role_id'] = $virtualFarmRoles[$role['farm_role_id']];
}
$update = true;
$dbFarmRole = DBFarmRole::LoadByID($role['farm_role_id']);
$dbRole = DBRole::loadById($dbFarmRole->RoleID);
$role['role_id'] = $dbFarmRole->RoleID;
if ($dbFarmRole->Platform == SERVER_PLATFORMS::GCE) {
$dbFarmRole->CloudLocation = $role['cloud_location'];
}
} else {
$update = false;
$dbRole = DBRole::loadById($role['role_id']);
$dbFarmRole = $dbFarm->AddRole($dbRole, $role['platform'], $role['cloud_location'], (int) $role['launch_index']);
//.........这里部分代码省略.........
示例12: xBuildAction
public function xBuildAction()
{
$this->request->defineParams(array('farmId' => array('type' => 'int'), 'roles' => array('type' => 'json'), 'rolesToRemove' => array('type' => 'json'), 'farm' => array('type' => 'json'), 'launch' => array('type' => 'bool')));
if (!$this->isFarmConfigurationValid($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'))) {
if ($this->errors['error_count'] != 0) {
$this->response->failure();
$this->response->data(array('errors' => $this->errors));
return;
}
}
$farm = $this->getParam('farm');
$client = Client::Load($this->user->getAccountId());
if ($this->getParam('farmId')) {
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
$this->request->checkPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_UPDATE);
$dbFarm->isLocked();
if ($this->getParam('changed') && $dbFarm->changedTime && $this->getParam('changed') != $dbFarm->changedTime) {
$userName = 'Someone';
$changed = explode(' ', $this->getParam('changed'));
$changedTime = intval($changed[1]);
try {
$user = new Scalr_Account_User();
$user->loadById($dbFarm->changedByUserId);
$userName = $user->getEmail();
} catch (Exception $e) {
}
$this->response->failure();
$this->response->data(array('changedFailure' => sprintf('%s changed this farm at %s', $userName, Scalr_Util_DateTime::convertTz($changedTime))));
return;
} else {
if ($this->getParam('changed')) {
$this->checkFarmConfigurationIntegrity($this->getParam('farmId'), $this->getParam('farm'), (array) $this->getParam('roles'), (array) $this->getParam('rolesToRemove'));
}
}
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
if ($this->getContainer()->analytics->enabled) {
$projectId = $farm['projectId'];
if (empty($projectId)) {
$ccId = $dbFarm->GetEnvironmentObject()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID);
if (!empty($ccId)) {
//Assigns Project automatically only if it is the one withing the Cost Center
$projects = ProjectEntity::findByCcId($ccId);
if (count($projects) == 1) {
$projectId = $projects->getArrayCopy()[0]->projectId;
}
}
}
if (!empty($projectId) && $dbFarm->GetSetting(Entity\FarmSetting::PROJECT_ID) != $projectId) {
$this->request->checkPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_PROJECTS);
}
}
$bNew = false;
} else {
$this->request->restrictAccess(Acl::RESOURCE_OWN_FARMS, Acl::PERM_FARMS_CREATE);
$this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_FARMS, 1);
$dbFarm = new DBFarm();
$dbFarm->ClientID = $this->user->getAccountId();
$dbFarm->EnvID = $this->getEnvironmentId();
$dbFarm->Status = FARM_STATUS::TERMINATED;
$dbFarm->ownerId = $this->user->getId();
$dbFarm->changedByUserId = $this->user->getId();
$dbFarm->changedTime = microtime();
$bNew = true;
}
if ($this->getParam('farm')) {
$dbFarm->Name = $this->request->stripValue($farm['name']);
$dbFarm->RolesLaunchOrder = $farm['rolesLaunchOrder'];
$dbFarm->Comments = $this->request->stripValue($farm['description']);
}
if (empty($dbFarm->Name)) {
throw new Exception(_("Farm name required"));
}
$setFarmTeams = false;
if ($bNew) {
$setFarmTeams = true;
} else {
if ($dbFarm->ownerId == $this->user->getId() || $this->request->hasPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_CHANGE_OWNERSHIP)) {
if (is_numeric($farm['owner']) && $farm['owner'] != $dbFarm->ownerId) {
$dbFarm->ownerId = $farm['owner'];
$f = Entity\Farm::findPk($dbFarm->ID);
Entity\FarmSetting::addOwnerHistory($f, User::findPk($farm['owner']), User::findPk($this->user->getId()));
$f->save();
}
$setFarmTeams = true;
}
}
$dbFarm->save();
if ($setFarmTeams && is_array($farm['teamOwner'])) {
/* @var $f Entity\Farm */
$f = Entity\Farm::findPk($dbFarm->ID);
$f->setTeams(empty($farm['teamOwner']) ? [] : Entity\Account\Team::find([['name' => ['$in' => $farm['teamOwner']]], ['accountId' => $this->getUser()->accountId]]));
$f->save();
}
if ($bNew) {
$dbFarm->SetSetting(Entity\FarmSetting::CREATED_BY_ID, $this->user->getId());
$dbFarm->SetSetting(Entity\FarmSetting::CREATED_BY_EMAIL, $this->user->getEmail());
}
$governance = new Scalr_Governance($this->getEnvironmentId());
//.........这里部分代码省略.........