mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-17 22:03:44 +02:00
Initial Commit of Files
PufferPanel v0.9 (Laravel) is now Pterodactyl 1.0
This commit is contained in:
63
app/Models/API.php
Normal file
63
app/Models/API.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Log;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
use Pterodactyl\Models\APIPermission;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class API extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'api';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['daemonSecret'];
|
||||
|
||||
public function permissions()
|
||||
{
|
||||
return $this->hasMany(APIPermission::class);
|
||||
}
|
||||
|
||||
public static function findKey($key)
|
||||
{
|
||||
return self::where('key', $key)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an API key has permission to perform an action.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $permission
|
||||
* @return boolean
|
||||
*/
|
||||
public static function checkPermission($key, $permission)
|
||||
{
|
||||
$api = self::findKey($key);
|
||||
|
||||
if (!$api) {
|
||||
throw new DisplayException('The requested API key (' . $key . ') was not found in the system.');
|
||||
}
|
||||
|
||||
return APIPermission::check($api->id, $permission);
|
||||
|
||||
}
|
||||
|
||||
public static function noPermissionError($error = 'You do not have permission to perform this action with this API key.')
|
||||
{
|
||||
return response()->json([
|
||||
'error' => 'You do not have permission to perform this action with this API key.'
|
||||
], 403);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user