63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Nami\Components;
|
|
|
|
use App\Initialize\Actions\NamiLoginCheckAction;
|
|
use App\Setting\NamiSettings;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
use Zoomyboy\LaravelNami\LoginException;
|
|
|
|
class SettingView extends Component
|
|
{
|
|
|
|
public $settingClass = NamiSettings::class;
|
|
|
|
#[Validate('required|string')]
|
|
public string $password = '';
|
|
#[Validate('required|string')]
|
|
public string $mglnr = '';
|
|
#[Validate('required|string')]
|
|
public string $default_group_id = '';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->mglnr = app(NamiSettings::class)->mglnr;
|
|
$this->default_group_id = app(NamiSettings::class)->default_group_id;
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$validated = $this->validate();
|
|
try {
|
|
NamiLoginCheckAction::run($this->only(['mglnr', 'password']));
|
|
app(NamiSettings::class)->fill($validated)->save();
|
|
$this->dispatch('success', 'Einstellungen gespeichert.');
|
|
} catch (LoginException $e) {
|
|
throw ValidationException::withMessages([
|
|
'mglnr' => 'Login fehlgeschlagen.',
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return <<<'HTML'
|
|
<x-page::setting-layout :active="$settingClass">
|
|
<x-slot:right>
|
|
<x-form::save-button form="namisettingform"></x-form::save-button>
|
|
</x-slot:right>
|
|
<form id="namisettingform" class="grow p-6 grid grid-cols-2 gap-3 items-start content-start" wire:submit.prevent="save">
|
|
<x-ui::setting-intro class="col-span-full">
|
|
Hier kannst du deine Zugangsdaten zu NaMi anpassen, falls sich z.B. dein Passwort geändert hat.
|
|
</x-ui::setting-intro>
|
|
<x-form::text name="mglnr" wire:model="mglnr" label="Mitgliedsnummer"></x-form::text>
|
|
<x-form::text name="default_group_id" wire:model="default_group_id" label="Standard-Gruppierung"></x-form::text>
|
|
<x-form::text name="password" wire:model="password" label="Passwort" name="password" type="password"></x-form::text>
|
|
</form>
|
|
</x-page::setting-layout>
|
|
HTML;
|
|
}
|
|
}
|