1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 00:15:51 +02:00
Files
php-flarum/src/Api/ApiKey.php
Daniël Klabbers bb0fc165af [b8] master token fix (#1622)
* fixed not being able to use master token because id column no longer holds key
* added flexibility of user_id column
* added tests to confirm the api keys actually work as intended
2018-11-07 22:34:09 +01:00

58 lines
1.1 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Api;
use Carbon\Carbon;
use Flarum\Database\AbstractModel;
use Flarum\User\User;
/**
* @property int $id
* @property string $key
* @property string|null $allowed_ips
* @property string|null $scopes
* @property int|null $user_id
* @property \Flarum\User\User|null $user
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon|null $last_activity_at
*/
class ApiKey extends AbstractModel
{
protected $dates = ['last_activity_at'];
/**
* Generate an API key.
*
* @return static
*/
public static function generate()
{
$key = new static;
$key->key = str_random(40);
return $key;
}
public function touch()
{
$this->last_activity_at = Carbon::now();
return $this->save();
}
public function user()
{
return $this->belongsTo(User::class);
}
}