2024-03-06 16:30:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Settings;
|
|
|
|
|
|
|
|
use App\Models\OauthSetting;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Livewire\Component;
|
2024-03-06 16:30:19 +00:00
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
class Auth extends Component
|
|
|
|
{
|
2024-03-06 16:30:19 +00:00
|
|
|
public $oauth_settings_map;
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
protected function rules()
|
|
|
|
{
|
|
|
|
return OauthSetting::all()->reduce(function ($carry, $setting) {
|
2024-03-06 16:30:19 +00:00
|
|
|
$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 20:43:34 +00:00
|
|
|
|
2024-03-06 16:30:19 +00:00
|
|
|
return $carry;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->oauth_settings_map = OauthSetting::all()->sortBy('provider')->reduce(function ($carry, $setting) {
|
2024-03-06 16:30:19 +00:00
|
|
|
$carry[$setting->provider] = $setting;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-06 16:30:19 +00:00
|
|
|
return $carry;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
private function updateOauthSettings()
|
|
|
|
{
|
2024-03-06 16:30:19 +00:00
|
|
|
foreach (array_values($this->oauth_settings_map) as &$setting) {
|
|
|
|
$setting->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
2024-03-06 16:30:19 +00:00
|
|
|
$this->updateOauthSettings();
|
|
|
|
}
|
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
2024-03-06 16:30:19 +00:00
|
|
|
$this->updateOauthSettings();
|
|
|
|
$this->dispatch('success', 'Instance settings updated successfully!');
|
|
|
|
}
|
|
|
|
}
|