Improve server and user model code to accept a specific user

This commit is contained in:
Dane Everitt 2017-04-15 12:48:47 -04:00
parent 2770e6d1b4
commit 0fe9a4566e
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 17 additions and 13 deletions

View file

@ -150,24 +150,32 @@ class Server extends Model
/**
* Returns non-administrative headers for accessing a server on the daemon.
*
* @param Pterodactyl\Models\User|null $user
* @return array
*/
public function guzzleHeaders()
public function guzzleHeaders(User $user = null)
{
// If no specific user is passed, see if we can find an active
// auth session to pull data from.
if (is_null($user) && Auth::check()) {
$user = Auth::user();
}
return [
'X-Access-Server' => $this->uuid,
'X-Access-Token' => Auth::user()->daemonToken($this),
'X-Access-Token' => ($user) ? $user->daemonToken($this) : $this->daemonSecret,
];
}
/**
* Return an instance of the Guzzle client for this specific server using defined access token.
*
* @param Pterodactyl\Models\User|null $user
* @return \GuzzleHttp\Client
*/
public function guzzleClient()
public function guzzleClient(User $user = null)
{
return $this->node->guzzleClient($this->guzzleHeaders());
return $this->node->guzzleClient($this->guzzleHeaders($user));
}
/**