|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: chenyihong |
|
5
|
|
|
* Date: 16/8/1 |
|
6
|
|
|
* Time: 14:53 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Leo108\CAS\Models; |
|
10
|
|
|
|
|
11
|
|
|
use Carbon\Carbon; |
|
12
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
13
|
|
|
use Leo108\CAS\Contracts\Models\UserModel; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Ticket |
|
17
|
|
|
* @package Leo108\CAS\Models |
|
18
|
|
|
* |
|
19
|
|
|
* @property integer $id |
|
20
|
|
|
* @property string $ticket |
|
21
|
|
|
* @property string $service_url |
|
22
|
|
|
* @property integer $service_id |
|
23
|
|
|
* @property integer $user_id |
|
24
|
|
|
* @property array $proxies |
|
25
|
|
|
* @property integer $created_at |
|
26
|
|
|
* @property integer $expire_at |
|
27
|
|
|
* @property UserModel $user |
|
28
|
|
|
*/ |
|
29
|
|
|
class Ticket extends Model |
|
30
|
|
|
{ |
|
31
|
|
|
protected $table = 'cas_tickets'; |
|
32
|
|
|
public $timestamps = false; |
|
33
|
|
|
protected $fillable = ['ticket', 'service_url', 'proxies', 'expire_at', 'created_at']; |
|
34
|
|
|
|
|
35
|
|
|
public function getProxiesAttribute() |
|
36
|
|
|
{ |
|
37
|
|
|
if (!$this->isProxy()) { |
|
38
|
|
|
return null; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return json_decode($this->attributes['proxies'], true); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function setProxiesAttribute($value) |
|
45
|
|
|
{ |
|
46
|
|
|
if ($this->id && !$this->isProxy()) { |
|
47
|
|
|
return; |
|
48
|
|
|
} |
|
49
|
|
|
$this->attributes['proxies'] = json_encode($value); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function isExpired() |
|
53
|
|
|
{ |
|
54
|
|
|
return (new Carbon($this->expire_at))->getTimestamp() < time(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function service() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->belongsTo(Service::class); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function user() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->belongsTo(config('cas.user_table.model'), 'user_id', config('cas.user_table.id')); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function isProxy() |
|
68
|
|
|
{ |
|
69
|
|
|
return !is_null($this->attributes['proxies']); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|