Add ApiKey service, cleanup old API key methods

https://zube.io/pterodactyl/panel/c/525
This commit is contained in:
Dane Everitt 2017-06-25 15:31:50 -05:00
parent 2235481765
commit 4ee9d38ad1
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
10 changed files with 569 additions and 85 deletions

View file

@ -24,16 +24,14 @@
namespace Pterodactyl\Models;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Validable;
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
class APIKey extends Model
class APIKey extends Model implements ValidableContract
{
/**
* Public key defined length used in verification methods.
*
* @var int
*/
const PUBLIC_KEY_LEN = 16;
use Eloquence, Validable;
/**
* The table associated with the model.
@ -65,6 +63,32 @@ class APIKey extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Rules defining what fields must be passed when making a model.
*
* @var array
*/
protected static $applicationRules = [
'memo' => 'required',
'user_id' => 'required',
'secret' => 'required',
'public' => 'required',
];
/**
* Rules to protect aganist invalid data entry to DB.
*
* @var array
*/
protected static $dataIntegrityRules = [
'user_id' => 'exists:users,id',
'public' => 'string|size:16',
'secret' => 'string',
'memo' => 'nullable|string|max:500',
'allowed_ips' => 'nullable|json',
'expires_at' => 'nullable|datetime',
];
/**
* Gets the permissions associated with a key.
*