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]; }
/** * @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'); } }
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(); }
/** * @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'); } }