Files
jeremy bayse 8f22dca9c8 Initial commit: CABM-IT (ItGlue-style MSP documentation platform)
Laravel 13 + Livewire/Volt app for managing client organizations,
documents, passwords, flexible assets, virtual machines, contacts,
domains, todos, shortcuts, and role-based user administration.
2026-08-16 13:28:12 +02:00

169 lines
7.4 KiB
PHP

<?php
use App\Models\Organization;
use App\Models\Password;
use Livewire\Component;
new class extends Component
{
public Organization $organization;
public ?Password $password = null;
public string $name = '';
public string $username = '';
public string $password_ciphertext = '';
public string $url = '';
public string $notes = '';
public bool $is_favorite = false;
public function mount(Organization $organization, ?Password $password = null): void
{
$this->organization = $organization;
if ($password?->exists) {
$this->password = $password;
$this->name = $password->name;
$this->username = $password->username ?? '';
// password_ciphertext intentionally left blank: never pre-fill a decrypted secret into the form.
$this->url = $password->url ?? '';
$this->notes = $password->notes ?? '';
$this->is_favorite = $password->is_favorite;
$password->logAction('viewed');
}
}
public function save(): void
{
$validated = $this->validate([
'name' => 'required|string|max:255',
'username' => 'nullable|string|max:255',
'password_ciphertext' => $this->password?->exists ? 'nullable|string' : 'required|string',
'url' => 'nullable|url|max:255',
'notes' => 'nullable|string',
'is_favorite' => 'boolean',
]);
if (blank($validated['password_ciphertext'])) {
unset($validated['password_ciphertext']);
} else {
$validated['password_updated_at'] = now();
}
if ($this->password?->exists) {
$isRotation = isset($validated['password_ciphertext']);
$this->password->update($validated);
$this->password->logAction($isRotation ? 'rotated' : 'updated');
session()->flash('status', "Mot de passe « {$this->password->name} » mis à jour.");
} else {
$validated['created_by'] = auth()->id();
$validated['password_updated_at'] = now();
$created = $this->organization->passwords()->create($validated);
$created->logAction('created');
session()->flash('status', "Mot de passe « {$this->name} » créé.");
}
$this->redirectRoute('organizations.passwords.index', $this->organization, navigate: true);
}
};
?>
<div class="max-w-2xl">
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
{{ $password?->exists ? 'Modifier le mot de passe' : 'Nouveau mot de passe' }}
</h1>
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
<div>
<label class="block text-sm font-medium text-slate-700">Nom</label>
<input type="text" wire:model="name"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-slate-700">Nom d'utilisateur</label>
<input type="text" wire:model="username"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
</div>
<div>
<label class="block text-sm font-medium text-slate-700">
Mot de passe
@if ($password?->exists) <span class="text-xs font-normal text-slate-400">(laisser vide pour conserver l'actuel)</span> @endif
</label>
<input type="password" wire:model="password_ciphertext" autocomplete="new-password"
class="mt-1 w-full rounded border-slate-300 font-mono text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('password_ciphertext') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
</div>
<div>
<label class="block text-sm font-medium text-slate-700">URL</label>
<input type="text" wire:model="url" placeholder="https://..."
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('url') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Notes</label>
<textarea wire:model="notes" rows="3"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
</div>
<label class="flex items-center gap-2 text-sm text-slate-700">
<input type="checkbox" wire:model="is_favorite" class="rounded border-slate-300">
Favori
</label>
<div class="flex items-center gap-3 pt-2">
<button type="submit"
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
Enregistrer
</button>
<a href="{{ route('organizations.passwords.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
</div>
</form>
@if ($password?->exists)
<div class="mt-8">
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Journal d'audit</h2>
<div class="overflow-hidden rounded border border-slate-200 bg-white">
<table class="min-w-full divide-y divide-slate-200 text-sm">
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
<tr>
<th class="px-4 py-2">Action</th>
<th class="px-4 py-2">Utilisateur</th>
<th class="px-4 py-2">IP</th>
<th class="px-4 py-2">Quand</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse ($password->auditLogs()->with('user')->latest()->limit(20)->get() as $log)
<tr>
<td class="px-4 py-2 capitalize text-slate-900">{{ $log->action }}</td>
<td class="px-4 py-2 text-slate-600">{{ $log->user?->name ?? 'système' }}</td>
<td class="px-4 py-2 text-slate-600">{{ $log->ip_address ?? '—' }}</td>
<td class="px-4 py-2 text-slate-500">{{ $log->created_at->diffForHumans() }}</td>
</tr>
@empty
<tr>
<td colspan="4" class="px-4 py-4 text-center text-slate-400">Aucune activité pour le moment.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<div class="mt-8">
<livewire:related-items.panel :organization="$organization" :item="$password" :key="'related-'.$password->id" />
</div>
@endif
</div>