Changeset View
Changeset View
Standalone View
Standalone View
src/app/CompanionApp.php
<?php | <?php | ||||
namespace App; | namespace App; | ||||
use Illuminate\Database\Eloquent\Model; | use Illuminate\Database\Eloquent\Model; | ||||
use App\Traits\UuidStrKeyTrait; | |||||
/** | /** | ||||
* The eloquent definition of a CompanionApp. | * The eloquent definition of a CompanionApp. | ||||
* | * | ||||
* A CompanionApp is an kolab companion app that the user registered | * A CompanionApp is an kolab companion app that the user registered | ||||
*/ | */ | ||||
class CompanionApp extends Model | class CompanionApp extends Model | ||||
{ | { | ||||
use UuidStrKeyTrait; | |||||
/** @var array<int, string> The attributes that are mass assignable */ | /** @var array<int, string> The attributes that are mass assignable */ | ||||
protected $fillable = [ | protected $fillable = [ | ||||
'name', | 'name', | ||||
'user_id', | 'user_id', | ||||
'device_id', | 'device_id', | ||||
'notification_token', | 'notification_token', | ||||
'mfa_enabled', | 'mfa_enabled', | ||||
]; | ]; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public static function notifyUser($userId, $data): bool | ||||
if (empty($notificationTokens)) { | if (empty($notificationTokens)) { | ||||
\Log::debug("There is no 2fa device to notify."); | \Log::debug("There is no 2fa device to notify."); | ||||
return false; | return false; | ||||
} | } | ||||
self::pushFirebaseNotification($notificationTokens, $data); | self::pushFirebaseNotification($notificationTokens, $data); | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Returns whether this companion app is paired with a device. | |||||
* | |||||
* @return bool | |||||
*/ | |||||
public function isPaired(): bool | |||||
{ | |||||
return !empty($this->device_id); | |||||
} | |||||
/** | |||||
* The PassportClient of this CompanionApp | |||||
* | |||||
* @return \App\Auth\PassportClient|null | |||||
*/ | |||||
public function passportClient() | |||||
{ | |||||
return \App\Auth\PassportClient::find($this->oauth_client_id); | |||||
} | |||||
/** | |||||
* Set the PassportClient of this CompanionApp | |||||
*/ | |||||
public function setPassportClient(\App\Auth\PassportClient $client) | |||||
{ | |||||
return $this->oauth_client_id = $client->id; | |||||
} | |||||
} | } |