This commit is contained in:
Andras Bacsai 2023-06-06 15:30:33 +02:00
parent 0fb8d74077
commit 05ee63cc83
7 changed files with 122 additions and 22 deletions

View File

@ -0,0 +1,60 @@
<?php
namespace App\Http\Livewire\Settings;
use App\Mail\TestTransactionalEmail;
use App\Models\InstanceSettings;
use Illuminate\Support\Facades\Mail;
use Livewire\Component;
class Email extends Component
{
public InstanceSettings $settings;
protected $rules = [
'settings.smtp_host' => 'required',
'settings.smtp_port' => 'required|numeric',
'settings.smtp_encryption' => 'nullable',
'settings.smtp_username' => 'nullable',
'settings.smtp_password' => 'nullable',
'settings.smtp_timeout' => 'nullable',
'settings.smtp_recipients' => 'required',
'settings.smtp_test_recipients' => 'nullable',
'settings.smtp_from_address' => 'required|email',
'settings.smtp_from_name' => 'required',
];
public function test_email()
{
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
"host" => $this->settings->smtp_host,
"port" => $this->settings->smtp_port,
"encryption" => $this->settings->smtp_encryption,
"username" => $this->settings->smtp_username,
"password" => $this->settings->smtp_password,
]);
$this->send_email();
}
public function test_email_local()
{
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
"host" => 'coolify-mail',
"port" => 1025,
]);
$this->send_email();
}
private function send_email()
{
}
public function submit()
{
$this->validate();
$this->settings->smtp_recipients = str_replace(' ', '', $this->settings->smtp_recipients);
$this->settings->smtp_test_recipients = str_replace(' ', '', $this->settings->smtp_test_recipients);
$this->settings->save();
}
}

View File

@ -21,8 +21,20 @@ return new class extends Migration
$table->boolean('do_not_track')->default(false);
$table->boolean('is_auto_update_enabled')->default(true);
$table->boolean('is_registration_enabled')->default(true);
// SMTP for transactional emails
$table->string('smtp_host')->nullable();
$table->integer('smtp_port')->nullable();
$table->string('smtp_encryption')->nullable();
$table->string('smtp_username')->nullable();
$table->string('smtp_password')->nullable();
$table->integer('smtp_timeout')->nullable();
$table->string('smtp_from_address')->nullable();
$table->string('smtp_from_name')->nullable();
$table->string('smtp_test_recipients')->nullable();
$table->string('smtp_recipients')->nullable();
// $table->string('custom_dns_servers')->default('1.1.1.1,8.8.8.8');
// $table->string('preview_domain_separator')->default('.');
// $table->boolean('is_dns_check_enabled')->default(true);
$table->timestamps();
});

View File

@ -1 +0,0 @@
Hello I am an example

0
resources/views/livewire/run-command.blade.php Executable file → Normal file
View File

View File

@ -1,18 +1,42 @@
<form>
<div class="flex flex-col gap-2">
<div class="flex gap-2">
<x-forms.input id="model.extra_attributes.smtp_host" label="Host" />
<x-forms.input id="model.extra_attributes.smtp_port" label="Port" />
<x-forms.input id="model.extra_attributes.smtp_encryption" label="Encryption" />
<div class="py-8">
<form wire:submit.prevent='submit' class="flex flex-col">
<div class="flex items-center gap-2">
<h3>Transactional Emails</h3>
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
<div class="flex gap-2">
<x-forms.input id="model.extra_attributes.smtp_username" label="Username" />
<x-forms.input id="model.extra_attributes.smtp_password" label="Password" />
<x-forms.input id="model.extra_attributes.smtp_timeout" label="Timeout" />
<div class="pt-2 pb-4 text-sm">SMTP settings for password reset, invitation, etc.</div>
<div class="flex items-end gap-2">
<x-forms.input required id="settings.smtp_recipients"
helper="Email list to send the all notifications to, separated by comma." label="Recipient(s)" />
<x-forms.input id="settings.smtp_test_recipients" label="Test Recipient(s)"
helper="Email list to send a test email to, separated by comma." />
<x-forms.button wire:click='test_email_local'>
Send Test Email (local Mailpit)
</x-forms.button>
<x-forms.button wire:click='test_email'>
Send Test Email (SMTP)
</x-forms.button>
</div>
<div class="flex gap-2">
<x-forms.input id="model.extra_attributes.from_address" label="From Address" />
<x-forms.input id="model.extra_attributes.from_name" label="From Name" />
<div class="flex flex-col gap-2 xl:flex-row">
<div class="flex flex-col w-96">
<x-forms.input required id="settings.smtp_host" helper="SMTP Hostname" placeholder="smtp.mailgun.org"
label="Host" />
<x-forms.input required id="settings.smtp_port" helper="SMTP Port" placeholder="587" label="Port" />
<x-forms.input id="settings.smtp_encryption" helper="If SMTP through SSL, set it to 'tls'."
placeholder="tls" label="Encryption" />
</div>
<div class="flex flex-col w-96">
<x-forms.input id="settings.smtp_username" helper="SMTP Username" label="Username" />
<x-forms.input id="settings.smtp_password" type="password" helper="SMTP Password" label="Password" />
<x-forms.input id="settings.smtp_timeout" helper="Timeout value for sending emails." label="Timeout" />
</div>
<div class="flex flex-col w-96">
<x-forms.input required id="settings.smtp_from_name" helper="Name used in emails." label="From Name" />
<x-forms.input required id="settings.smtp_from_address" helper="Email address used in emails."
label="From Address" />
</div>
</div>
</div>
</form>
</form>
</div>

View File

@ -1,12 +1,13 @@
<div>
<form wire:submit.prevent='submit' class="flex flex-col pb-8">
<form wire:submit.prevent='submit' class="flex flex-col">
<h1>Settings</h1>
<div class="pt-2 pb-4 text-sm">Instance wide settings for Coolify. </div>
<div class="flex items-center gap-2">
<h1>Settings</h1>
<h3>General</h3>
<x-forms.button type="submit">
Save
</x-forms.button>
</div>
<div class="pt-2 pb-4 text-sm">Instance wide settings for Coolify.</div>
<div class="flex flex-col gap-2">
<div class="flex gap-2">
<x-forms.input id="settings.fqdn" label="Coolify's Domain" />
@ -21,11 +22,11 @@
</div>
</div>
</form>
<h3>Advanced</h3>
<h3 class="pt-6">Advanced</h3>
<div class="flex flex-col text-right w-52">
<x-forms.checkbox instantSave id="is_auto_update_enabled" label="Auto Update Coolify" />
<x-forms.checkbox instantSave id="is_registration_enabled" label="Registration Allowed" />
{{-- <x-forms.checkbox instantSave id="is_https_forced" label="Force https?" /> --}}
<x-forms.checkbox instantSave id="do_not_track" label="Do Not Track" />
</div>
</div>

View File

@ -1,5 +1,9 @@
<x-layout>
<livewire:settings.form :settings="$settings" />
<livewire:settings.email :settings="$settings" />
<h3 class='pb-4'>Actions</h3>
@if (auth()->user()->isPartOfRootTeam())
<livewire:force-upgrade />
@endif