Deploy Ladill Events / deploy (push) Successful in 28s
Attendee and speaker comms use encrypted tenant relay credentials and skip platform-key fallback and Bird wallet double-debit. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
|
|
class MessagingCredential extends Model
|
|
{
|
|
public const STATUS_VALID = 'valid';
|
|
|
|
public const STATUS_INVALID = 'invalid';
|
|
|
|
protected $table = 'events_messaging_credentials';
|
|
|
|
protected $fillable = [
|
|
'owner_ref',
|
|
'sms_api_key_encrypted',
|
|
'sms_api_key_prefix',
|
|
'sms_sender_id',
|
|
'sms_status',
|
|
'sms_validated_at',
|
|
'sms_last_error',
|
|
'bird_api_key_encrypted',
|
|
'bird_api_key_prefix',
|
|
'bird_from_email',
|
|
'bird_from_name',
|
|
'bird_status',
|
|
'bird_validated_at',
|
|
'bird_last_error',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'sms_api_key_encrypted',
|
|
'bird_api_key_encrypted',
|
|
];
|
|
|
|
protected $casts = [
|
|
'sms_validated_at' => 'datetime',
|
|
'bird_validated_at' => 'datetime',
|
|
];
|
|
|
|
public function hasValidSms(): bool
|
|
{
|
|
return $this->sms_status === self::STATUS_VALID
|
|
&& filled($this->sms_api_key_encrypted)
|
|
&& filled($this->sms_sender_id);
|
|
}
|
|
|
|
public function hasValidBird(): bool
|
|
{
|
|
return $this->bird_status === self::STATUS_VALID
|
|
&& filled($this->bird_api_key_encrypted)
|
|
&& filled($this->bird_from_email);
|
|
}
|
|
|
|
public function smsApiKey(): ?string
|
|
{
|
|
if (! filled($this->sms_api_key_encrypted)) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
return Crypt::decryptString($this->sms_api_key_encrypted);
|
|
} catch (\Throwable) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function birdApiKey(): ?string
|
|
{
|
|
if (! filled($this->bird_api_key_encrypted)) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
return Crypt::decryptString($this->bird_api_key_encrypted);
|
|
} catch (\Throwable) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public static function encryptKey(string $plain): string
|
|
{
|
|
return Crypt::encryptString($plain);
|
|
}
|
|
}
|