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; | ||||
/** | /** | ||||
* 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 | ||||
{ | { | ||||
/** @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 All 40 Lines | class CompanionApp extends Model | ||||
/** | /** | ||||
* Send a notification to a user. | * Send a notification to a user. | ||||
* | * | ||||
* @throws \Exception on notification failure | * @throws \Exception on notification failure | ||||
* @return bool true if a notification has been sent | * @return bool true if a notification has been sent | ||||
*/ | */ | ||||
public static function notifyUser($userId, $data): bool | public static function notifyUser($userId, $data): bool | ||||
{ | { | ||||
$notificationTokens = \App\CompanionApp::where('user_id', $userId) | $notificationTokens = CompanionApp::where('user_id', $userId) | ||||
->where('mfa_enabled', true) | ->where('mfa_enabled', true) | ||||
->pluck('notification_token') | ->pluck('notification_token') | ||||
->all(); | ->all(); | ||||
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; | ||||
} | } | ||||
} | } |