1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\TwoFactorAuth\Models;
9:
10: use Aurora\System\Classes\Model;
11: use Aurora\Modules\Core\Models\User;
12:
13: /**
14: * Aurora\Modules\TwoFactorAuth\Models\UsedDevice
15: *
16: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
17: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
18: * @copyright Copyright (c) 2023, Afterlogic Corp.
19: * @package Api
20: * @property integer $Id
21: * @property integer $UserId
22: * @property string $DeviceId
23: * @property string $DeviceName
24: * @property string $DeviceCustomName
25: * @property string $AuthToken
26: * @property integer $CreationDateTime
27: * @property integer $LastUsageDateTime
28: * @property integer $TrustTillDateTime
29: * @property string $DeviceIP
30: * @property \Illuminate\Support\Carbon|null $CreatedAt
31: * @property \Illuminate\Support\Carbon|null $UpdatedAt
32: * @property-read mixed $entity_id
33: * @method static int count(string $columns = '*')
34: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice find(int|string $id, array|string $columns = ['*'])
35: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice findOrFail(int|string $id, mixed $id, Closure|array|string $columns = ['*'], Closure $callback = null)
36: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice first(array|string $columns = ['*'])
37: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice firstWhere(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
38: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice newModelQuery()
39: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice newQuery()
40: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice query()
41: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice where(Closure|string|array|\Illuminate\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
42: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereAuthToken($value)
43: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereCreatedAt($value)
44: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereCreationDateTime($value)
45: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereDeviceIP($value)
46: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereDeviceId($value)
47: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereDeviceName($value)
48: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereId($value)
49: * @method static \Illuminate\Database\Eloquent\Builder|\Aurora\Modules\TwoFactorAuth\Models\UsedDevice whereIn(string $column, mixed $values, string $boolean = 'and', bool $not = false)
50: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereLastUsageDateTime($value)
51: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereTrustTillDateTime($value)
52: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereUpdatedAt($value)
53: * @method static \Illuminate\Database\Eloquent\Builder|UsedDevice whereUserId($value)
54: * @mixin \Eloquent
55: */
56: class UsedDevice extends Model
57: {
58: protected $table = 'security_used_devices';
59: protected $foreignModel = User::class;
60: protected $foreignModelIdColumn = 'UserId'; // Column that refers to an external table
61:
62: protected $fillable = [
63: 'Id',
64: 'UserId',
65: 'DeviceId',
66: 'DeviceName',
67: 'DeviceCustomName',
68: 'AuthToken',
69: 'CreationDateTime',
70: 'LastUsageDateTime',
71: 'TrustTillDateTime',
72: 'DeviceIP'
73: ];
74:
75: public function toResponseArray()
76: {
77: $aResponse = parent::toResponseArray();
78: $aResponse['Authenticated'] = false;
79: if (\Aurora\Api::GetSettings()->StoreAuthTokenInDB) {
80: if (!empty($aResponse['AuthToken']) && !empty(\Aurora\System\Api::UserSession()->Get($aResponse['AuthToken']))) {
81: $aResponse['Authenticated'] = true;
82: }
83: } elseif (!empty($aResponse['AuthToken'])) {
84: $aResponse['Authenticated'] = true;
85: }
86: unset($aResponse['AuthToken']);
87: return $aResponse;
88: }
89: }
90: