VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
73 lines
1.8 KiB
PHP
73 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class HostingAccountMember extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const ROLE_DEVELOPER = 'developer';
|
|
|
|
private const SSH_KEY_PATTERN = '/^(ssh-(ed25519|rsa)|ecdsa-sha2-nistp(256|384|521)|sk-ssh-ed25519@openssh\\.com|sk-ecdsa-sha2-nistp256@openssh\\.com) [A-Za-z0-9+\\/]+={0,3}(?: .+)?$/';
|
|
|
|
protected $fillable = [
|
|
'hosting_account_id',
|
|
'user_id',
|
|
'invited_by_user_id',
|
|
'role',
|
|
'invited_at',
|
|
'ssh_public_key',
|
|
'ssh_key_installed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'invited_at' => 'datetime',
|
|
'ssh_key_installed_at' => 'datetime',
|
|
];
|
|
|
|
public function hostingAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(HostingAccount::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function invitedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'invited_by_user_id');
|
|
}
|
|
|
|
public function sshKeyMarker(): string
|
|
{
|
|
return 'ladill-team-member-'.$this->id;
|
|
}
|
|
|
|
public function hasSshAccessKey(): bool
|
|
{
|
|
return filled($this->ssh_public_key);
|
|
}
|
|
|
|
public static function normalizeSshPublicKey(string $value): string
|
|
{
|
|
return trim(preg_replace('/\s+/', ' ', trim($value)) ?? '');
|
|
}
|
|
|
|
public static function looksLikeSshPublicKey(?string $value): bool
|
|
{
|
|
if (! is_string($value)) {
|
|
return false;
|
|
}
|
|
|
|
$normalized = static::normalizeSshPublicKey($value);
|
|
|
|
return $normalized !== '' && preg_match(self::SSH_KEY_PATTERN, $normalized) === 1;
|
|
}
|
|
}
|