public function gotosite($site = null) { if ($this->GetData('site')) { $site = $this->GetData('site'); } $site = Website::find_by_code($site); if (!$site) { Site::Flash('error', 'Unable to find the site you want to go to'); Redirect(''); } if ($user = Site::CurrentUser()) { try { $login = new Login(); $login->user_id = $user->id; $login->user = $user; $login->website_id = $site->id; $login->website = $site; $login->ip = Site::RemoteIP(); if ($login->save()) { header("Location: {$login->url}"); die; } else { Site::Flash('error', 'Unable to redirect you'); Redirect(''); } } catch (Error500 $e) { $error = 'Error'; if ($e->getMessage()) { $error .= ': ' . $e->getMessage(); } Site::Flash('error', $error); Redirect(''); } } else { if ($site) { header("Location: {$site->url}"); die; } Site::Flash('error', 'Unable to go to site'); Redirect(''); } }
/** * Retrieves a one time URL for a login into a website * * @arg string The RPCSession code * @arg int The user ID to login * @arg string The name of the site * @arg string The IP of the user * * @param object $method The name of the RPC method * @param object $args An array of arguements, listed above * @return string The URL to use to access that site * @throws RPCException */ public function xlogin($method, $args) { $this->auth($args[0]); if (count($args) < 4) { throw new RPCException('Invalid Arguements', 500); } $user = User::find_by_id($args[1]); if (!$user) { throw new RPCException('Unable to find user', 500); } $site = Website::find_by_code($args[2]); if (!$site) { throw new RPCException('Unable to find site', 500); } $destination = ''; if (isset($args[4])) { $destination = $args[4]; } $login = new Login(); $login->user_id = $user->id; $login->user = $user; $login->website_id = $site->id; $login->website = $site; $login->destination = $destination; $login->ip = $args[3]; if ($login->save()) { return $login->url; } else { throw new RPCException($login->errorString(), 500); } }