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();
}