loadById() public method

public loadById ( $id ) : Scalr_Account
return Scalr_Account
Esempio n. 1
0
 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];
 }
Esempio n. 2
0
 /**
  * Return account's hash. It's used for reseting keepSession on a whole account
  *
  * @param   int     $userId
  * @return  string
  */
 protected static function getAccountHash($userId)
 {
     $db = \Scalr::getDb();
     $hash = $db->GetOne("\n            SELECT `value`\n            FROM client_settings\n            JOIN account_users ON account_users.account_id = client_settings.clientid\n            WHERE `key` = ? AND account_users.id = ?\n            LIMIT 1\n        ", array(Scalr_Account::SETTING_AUTH_HASH, $userId));
     if (!$hash) {
         $accountId = $db->GetOne('SELECT account_id FROM account_users WHERE id = ? LIMIT 1', array($userId));
         if ($accountId) {
             $hash = CryptoTool::sault();
             $acc = new Scalr_Account();
             $acc->loadById($accountId);
             $acc->setSetting(Scalr_Account::SETTING_AUTH_HASH, $hash);
         }
     }
     return $hash;
 }
Esempio n. 3
0
 /**
  * @param  int     $accountId
  * @param  RawData $password
  * @param  RawData $currentPassword
  * @throws Exception
  */
 public function xSaveOwnerPasswordAction($accountId, RawData $password, RawData $currentPassword)
 {
     $account = new Scalr_Account();
     $account->loadById($accountId);
     $password = (string) $password;
     $validator = new Validator();
     $validator->addErrorIf(!$this->user->checkPassword($currentPassword), "currentPassword", "Invalid password");
     $validator->validate($password, "password", Validator::PASSWORD, ['admin']);
     if ($validator->isValid($this->response)) {
         $user = $account->getOwner();
         $user->updatePassword($password);
         $user->save();
         // Send notification E-mail
         $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);
         $this->response->success('Password successfully updated');
     }
 }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 /**
  * @param int $accountId
  * @param RawData $password
  * @param RawData $cpassword
  * @param RawData $currentPassword
  * @throws Exception
  */
 public function xSaveOwnerPasswordAction($accountId, $password, $cpassword, $currentPassword)
 {
     $account = new Scalr_Account();
     $account->loadById($accountId);
     $validator = new Validator();
     $validator->addErrorIf(!$this->user->checkPassword($currentPassword), ['currentPassword'], 'Invalid password');
     $validator->validate($password, 'password', Validator::NOEMPTY);
     $validator->validate($cpassword, 'cpassword', Validator::NOEMPTY);
     $validator->addErrorIf($password && $cpassword && $password != $cpassword, ['password', 'cpassword'], 'Two passwords are not equal');
     if ($validator->isValid($this->response)) {
         $user = $account->getOwner();
         $user->updatePassword($password);
         $user->save();
         // Send notification E-mail
         $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);
         $this->response->success('Password successfully updated');
     }
 }