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