Improve server and user model code to accept a specific user
This commit is contained in:
parent
2770e6d1b4
commit
0fe9a4566e
|
@ -150,24 +150,32 @@ class Server extends Model
|
||||||
/**
|
/**
|
||||||
* Returns non-administrative headers for accessing a server on the daemon.
|
* Returns non-administrative headers for accessing a server on the daemon.
|
||||||
*
|
*
|
||||||
|
* @param Pterodactyl\Models\User|null $user
|
||||||
* @return array
|
* @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 [
|
return [
|
||||||
'X-Access-Server' => $this->uuid,
|
'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.
|
* Return an instance of the Guzzle client for this specific server using defined access token.
|
||||||
*
|
*
|
||||||
|
* @param Pterodactyl\Models\User|null $user
|
||||||
* @return \GuzzleHttp\Client
|
* @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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -176,13 +176,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
||||||
return $server->daemonSecret;
|
return $server->daemonSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subuser = Subuser::where('server_id', $server->id)->where('user_id', $this->id)->first();
|
$subuser = $this->subuserOf->where('server_id', $server->id)->first();
|
||||||
|
|
||||||
if (is_null($subuser)) {
|
return ($subuser) ? $subuser->daemonSecret : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $subuser->daemonSecret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,9 +189,9 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
|
||||||
*/
|
*/
|
||||||
public function serverAccessArray()
|
public function serverAccessArray()
|
||||||
{
|
{
|
||||||
$union = Subuser::select('server_id')->where('user_id', $this->id);
|
return Server::select('id')->where('owner_id', $this->id)->union(
|
||||||
|
Subuser::select('server_id')->where('user_id', $this->id)
|
||||||
return Server::select('id')->where('owner_id', $this->id)->union($union)->pluck('id')->all();
|
)->pluck('id')->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue