coolify/app/Livewire/Help.php

91 lines
2.6 KiB
PHP
Raw Normal View History

2023-09-02 13:37:25 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire;
2023-09-02 13:37:25 +00:00
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Http;
use Livewire\Attributes\Validate;
2023-09-02 13:37:25 +00:00
use Livewire\Component;
class Help extends Component
{
use WithRateLimiting;
2024-06-10 20:43:34 +00:00
#[Validate(['required', 'min:10', 'max:1000'])]
2023-09-02 13:37:25 +00:00
public string $description;
2024-06-10 20:43:34 +00:00
#[Validate(['required', 'min:3'])]
2023-09-02 13:37:25 +00:00
public string $subject;
2024-06-10 20:43:34 +00:00
2023-09-02 13:37:25 +00:00
public function submit()
{
try {
$this->validate();
$this->rateLimit(3, 30);
$settings = instanceSettings();
2024-07-24 19:11:12 +00:00
$mail = new MailMessage;
2023-09-02 13:37:25 +00:00
$mail->view(
'emails.help',
[
'description' => $this->description,
]
);
$mail->subject("[HELP]: {$this->subject}");
$type = set_transanctional_email_settings($settings);
// Sending feedback through Cloud API
if ($type === false) {
2024-06-10 20:43:34 +00:00
$url = 'https://app.coolify.io/api/feedback';
Http::post($url, [
2024-06-10 20:43:34 +00:00
'content' => 'User: `'.auth()->user()?->email.'` with subject: `'.$this->subject.'` has the following problem: `'.$this->description.'`',
]);
} else {
2024-06-10 20:43:34 +00:00
send_user_an_email($mail, auth()->user()?->email, 'hi@coollabs.io');
}
$this->dispatch('success', 'Feedback sent.', 'We will get in touch with you as soon as possible.');
$this->reset('description', 'subject');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-09-02 13:37:25 +00:00
}
}
2024-06-10 20:43:34 +00:00
2023-09-02 13:37:25 +00:00
public function render()
{
return view('livewire.help')->layout('layouts.app');
}
}
function set_transanctional_email_settings($settings = null)
{
if (is_null($settings)) {
$settings = instanceSettings();
}
if ($settings->resend_enabled) {
config()->set('mail.default', 'resend');
config()->set('resend.api_key', $settings->resend_api_key);
return 'resend';
}
if ($settings->smtp_enabled) {
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
'transport' => 'smtp',
'host' => $settings->smtp_host,
'port' => $settings->smtp_port,
'encryption' => $settings->smtp_encryption === 'none' ? null : $settings->smtp_encryption,
'username' => $settings->smtp_username,
'password' => $settings->smtp_password,
'timeout' => $settings->smtp_timeout,
'local_domain' => null,
]);
return 'smtp';
}
return false;
}