mirror of
https://github.com/flarum/core.git
synced 2025-08-06 08:27:42 +02:00
new api tests uncovered more issues, fixed tokens and discussion posts
This commit is contained in:
@@ -13,12 +13,13 @@ namespace Flarum\Http;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\User\User;
|
||||
|
||||
/**
|
||||
* @property string $id
|
||||
* @property string $token
|
||||
* @property int $user_id
|
||||
* @property int $last_activity
|
||||
* @property int $lifetime
|
||||
* @property int $last_activity_at
|
||||
* @property int $lifetime_seconds
|
||||
* @property \Flarum\User\User|null $user
|
||||
*/
|
||||
class AccessToken extends AbstractModel
|
||||
@@ -35,6 +36,10 @@ class AccessToken extends AbstractModel
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected $primaryKey = 'token';
|
||||
|
||||
protected $dates = ['last_activity_at'];
|
||||
|
||||
/**
|
||||
* Generate an access token for the specified user.
|
||||
*
|
||||
@@ -46,17 +51,17 @@ class AccessToken extends AbstractModel
|
||||
{
|
||||
$token = new static;
|
||||
|
||||
$token->id = str_random(40);
|
||||
$token->token = str_random(40);
|
||||
$token->user_id = $userId;
|
||||
$token->last_activity = Carbon::now();
|
||||
$token->lifetime = $lifetime;
|
||||
$token->last_activity_at = Carbon::now();
|
||||
$token->lifetime_seconds = $lifetime;
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function touch()
|
||||
{
|
||||
$this->last_activity = Carbon::now();
|
||||
$this->last_activity_at = Carbon::now();
|
||||
|
||||
return $this->save();
|
||||
}
|
||||
@@ -68,6 +73,6 @@ class AccessToken extends AbstractModel
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('Flarum\User\User');
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user