Push basis of new API key policy

Will need to revisit this another day when I’m fresh to figure out the
best method to do this.
This commit is contained in:
Dane Everitt 2017-04-07 21:25:17 -04:00
parent 51204b8d9d
commit db4df2bfa1
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 104 additions and 19 deletions

View file

@ -25,6 +25,7 @@
namespace Pterodactyl\Providers;
use File;
use Request;
use Illuminate\Support\ServiceProvider;
class MacroServiceProvider extends ServiceProvider
@ -48,5 +49,19 @@ class MacroServiceProvider extends ServiceProvider
return round($size, ($i < 2) ? 0 : $precision) . ' ' . $units[$i];
});
Request::macro('apiKey', function () {
if (! Request::bearerToken()) {
return false;
}
$parts = explode('.', Request::bearerToken());
if (count($parts) === 2) {
return \Pterodactyl\Models\APIKey::where('public', $parts[0])->first();
}
return false;
});
}
}