coolify/app/Livewire/Settings/Auth.php

52 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Livewire\Settings;
use App\Models\OauthSetting;
2024-06-10 22:43:34 +02:00
use Livewire\Component;
2024-06-10 22:43:34 +02:00
class Auth extends Component
{
public $oauth_settings_map;
2024-06-10 22:43:34 +02:00
protected function rules()
{
return OauthSetting::all()->reduce(function ($carry, $setting) {
$carry["oauth_settings_map.$setting->provider.enabled"] = 'required';
$carry["oauth_settings_map.$setting->provider.client_id"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.client_secret"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.redirect_uri"] = 'nullable';
$carry["oauth_settings_map.$setting->provider.tenant"] = 'nullable';
2024-06-10 22:43:34 +02:00
return $carry;
}, []);
}
2024-06-10 22:43:34 +02:00
public function mount()
{
$this->oauth_settings_map = OauthSetting::all()->sortBy('provider')->reduce(function ($carry, $setting) {
$carry[$setting->provider] = $setting;
2024-06-10 22:43:34 +02:00
return $carry;
}, []);
}
2024-06-10 22:43:34 +02:00
private function updateOauthSettings()
{
foreach (array_values($this->oauth_settings_map) as &$setting) {
$setting->save();
}
}
2024-06-10 22:43:34 +02:00
public function instantSave()
{
$this->updateOauthSettings();
}
2024-06-10 22:43:34 +02:00
public function submit()
{
$this->updateOauthSettings();
$this->dispatch('success', 'Instance settings updated successfully!');
}
}