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: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
15: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
16: * @copyright Copyright (c) 2023, Afterlogic Corp.
17: *
18: * @package Api
19: */
20: class UsedDevice extends Model
21: {
22: protected $table = 'security_used_devices';
23: protected $foreignModel = User::class;
24: protected $foreignModelIdColumn = 'UserId'; // Column that refers to an external table
25:
26:
27: protected $fillable = [
28: 'Id',
29: 'UserId',
30: 'DeviceId',
31: 'DeviceName',
32: 'AuthToken',
33: 'CreationDateTime',
34: 'LastUsageDateTime',
35: 'TrustTillDateTime',
36: 'DeviceIP'
37: ];
38:
39: public function toResponseArray()
40: {
41: $aResponse = parent::toResponseArray();
42: $aResponse['Authenticated'] = false;
43: if (\Aurora\Api::GetSettings()->GetValue('StoreAuthTokenInDB', false) && !empty($aResponse['AuthToken']) && !empty(\Aurora\System\Api::UserSession()->Get($aResponse['AuthToken']))) {
44: $aResponse['Authenticated'] = true;
45: }
46: unset($aResponse['AuthToken']);
47: return $aResponse;
48: }
49: }
50: