1 | <?php |
||
2 | |||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
3 | namespace BristolSU\Service\Typeform\Models; |
||
4 | |||
5 | use BristolSU\Support\User\Contracts\UserAuthentication; |
||
6 | use Illuminate\Database\Eloquent\Builder; |
||
7 | use Illuminate\Database\Eloquent\Model; |
||
8 | use Carbon\Carbon; |
||
9 | use Illuminate\Support\Facades\Crypt; |
||
10 | |||
11 | class TypeformAuthCode extends Model |
||
0 ignored issues
–
show
|
|||
12 | { |
||
13 | |||
14 | protected $hidden = [ |
||
15 | 'auth_code', 'expires_at', 'refresh_token' |
||
16 | ]; |
||
17 | |||
18 | protected $casts = [ |
||
19 | 'expires_at' => 'datetime' |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * Scope auth codes to show to the user to select. |
||
24 | * |
||
25 | * These auth codes must both belong to the user, and have been created in the last 10 minutes. |
||
26 | * |
||
27 | * @param Builder $query |
||
0 ignored issues
–
show
|
|||
28 | */ |
||
0 ignored issues
–
show
|
|||
29 | 2 | public function scopeValid(Builder $query) |
|
30 | { |
||
31 | 2 | $query->where('user_id', app(UserAuthentication::class)->getUser()->control_id) |
|
32 | 2 | ->where('created_at', '>=', Carbon::now()->subMinutes(10)) |
|
33 | 2 | ->orderBy('created_at', 'DESC'); |
|
34 | 2 | } |
|
35 | |||
36 | 8 | public function isValid() |
|
0 ignored issues
–
show
|
|||
37 | { |
||
38 | 8 | return $this->expires_at->isFuture(); |
|
39 | } |
||
40 | |||
41 | 16 | public function setAuthCodeAttribute($authCode) |
|
0 ignored issues
–
show
|
|||
42 | { |
||
43 | 16 | $this->attributes['auth_code'] = Crypt::encrypt($authCode); |
|
44 | 16 | } |
|
45 | |||
46 | 6 | public function getAuthCodeAttribute($authCode) |
|
0 ignored issues
–
show
|
|||
47 | { |
||
48 | 6 | return Crypt::decrypt($authCode); |
|
49 | } |
||
50 | |||
51 | 16 | public function setRefreshTokenAttribute($refreshToken) |
|
0 ignored issues
–
show
|
|||
52 | { |
||
53 | 16 | $this->attributes['refresh_token'] = Crypt::encrypt($refreshToken); |
|
54 | 16 | } |
|
55 | |||
56 | 3 | public function getRefreshTokenAttribute($refreshToken) |
|
0 ignored issues
–
show
|
|||
57 | { |
||
58 | 3 | return Crypt::decrypt($refreshToken); |
|
59 | } |
||
60 | |||
61 | } |