2023-05-25 16:27:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Notifications;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use App\Models\Team;
|
2023-06-01 10:15:33 +00:00
|
|
|
use App\Notifications\TestNotification;
|
2023-05-25 16:44:24 +00:00
|
|
|
use Illuminate\Support\Facades\Notification;
|
2023-05-25 16:27:52 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class EmailSettings extends Component
|
|
|
|
{
|
|
|
|
public Team|Server $model;
|
|
|
|
|
|
|
|
protected $rules = [
|
2023-06-01 11:24:20 +00:00
|
|
|
'model.extra_attributes.smtp_active' => 'nullable|boolean',
|
|
|
|
'model.extra_attributes.from_address' => 'required|email',
|
|
|
|
'model.extra_attributes.from_name' => 'required',
|
|
|
|
'model.extra_attributes.recipients' => 'required',
|
|
|
|
'model.extra_attributes.smtp_host' => 'required',
|
|
|
|
'model.extra_attributes.smtp_port' => 'required',
|
|
|
|
'model.extra_attributes.smtp_encryption' => 'nullable',
|
|
|
|
'model.extra_attributes.smtp_username' => 'nullable',
|
|
|
|
'model.extra_attributes.smtp_password' => 'nullable',
|
|
|
|
'model.extra_attributes.smtp_timeout' => 'nullable',
|
|
|
|
'model.extra_attributes.test_notification_email' => 'nullable|email',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
2023-06-01 11:24:20 +00:00
|
|
|
'model.extra_attributes.from_address' => 'From Address',
|
|
|
|
'model.extra_attributes.from_name' => 'From Name',
|
|
|
|
'model.extra_attributes.recipients' => 'Recipients',
|
|
|
|
'model.extra_attributes.smtp_host' => 'Host',
|
|
|
|
'model.extra_attributes.smtp_port' => 'Port',
|
|
|
|
'model.extra_attributes.smtp_encryption' => 'Encryption',
|
|
|
|
'model.extra_attributes.smtp_username' => 'Username',
|
|
|
|
'model.extra_attributes.smtp_password' => 'Password',
|
2023-05-25 16:27:52 +00:00
|
|
|
];
|
|
|
|
public function mount($model)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->resetErrorBag();
|
|
|
|
$this->validate();
|
2023-06-01 10:15:33 +00:00
|
|
|
$this->saveModel();
|
|
|
|
}
|
|
|
|
private function saveModel()
|
|
|
|
{
|
2023-05-25 16:27:52 +00:00
|
|
|
$this->model->save();
|
2023-06-01 10:15:33 +00:00
|
|
|
if (is_a($this->model, Team::class)) {
|
2023-05-25 16:27:52 +00:00
|
|
|
session(['currentTeam' => $this->model]);
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 10:15:33 +00:00
|
|
|
public function instantSave()
|
2023-05-25 16:27:52 +00:00
|
|
|
{
|
2023-06-01 11:24:20 +00:00
|
|
|
try {
|
|
|
|
$this->submit();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->model->extra_attributes->smtp_active = false;
|
|
|
|
$this->validate();
|
|
|
|
}
|
2023-05-25 16:27:52 +00:00
|
|
|
}
|
|
|
|
}
|