This commit is contained in:
Andras Bacsai 2023-06-20 21:18:14 +02:00
parent d4976c6eb6
commit 4a1378debd
4 changed files with 49 additions and 2 deletions

View File

@ -39,6 +39,19 @@ class EmailSettings extends Component
'model.smtp.password' => 'Password',
'model.smtp.test_recipients' => 'Test Recipients',
];
private function decrypt()
{
if (data_get($this->model, 'smtp.password')) {
try {
$this->model->smtp->password = decrypt($this->model->smtp->password);
} catch (\Exception $e) {
}
}
}
public function mount()
{
$this->decrypt();
}
public function copyFromInstanceSettings()
{
$settings = InstanceSettings::get();
@ -63,6 +76,13 @@ public function submit()
{
$this->resetErrorBag();
$this->validate();
if ($this->model->smtp->password) {
$this->model->smtp->password = encrypt($this->model->smtp->password);
} else {
$this->model->smtp->password = null;
}
$this->model->smtp->recipients = str_replace(' ', '', $this->model->smtp->recipients);
$this->model->smtp->test_recipients = str_replace(' ', '', $this->model->smtp->test_recipients);
$this->saveModel();

View File

@ -34,6 +34,10 @@ class Email extends Component
'settings.smtp.password' => 'Password',
'settings.smtp.test_recipients' => 'Test Recipients',
];
public function mount()
{
$this->decrypt();
}
public function instantSave()
{
try {
@ -48,10 +52,27 @@ public function test_email()
Notification::send($this->settings, new TestEmail);
$this->emit('success', 'Test email sent.');
}
private function decrypt()
{
if (data_get($this->settings, 'smtp.password')) {
try {
$this->settings->smtp->password = decrypt($this->settings->smtp->password);
} catch (\Exception $e) {
}
}
}
public function submit()
{
$this->resetErrorBag();
$this->validate();
if ($this->settings->smtp->password) {
$this->settings->smtp->password = encrypt($this->settings->smtp->password);
} else {
$this->settings->smtp->password = null;
}
$this->settings->smtp->test_recipients = str_replace(' ', '', $this->settings->smtp->test_recipients);
$this->settings->save();
$this->decrypt();
}
}

View File

@ -35,6 +35,9 @@ public function send(SendsEmail $notifiable, Notification $notification): void
private function bootConfigs($notifiable): void
{
$password = data_get($notifiable, 'smtp.password');
if ($password) $password = decrypt($password);
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
@ -42,7 +45,7 @@ private function bootConfigs($notifiable): void
"port" => data_get($notifiable, 'smtp.port'),
"encryption" => data_get($notifiable, 'smtp.encryption'),
"username" => data_get($notifiable, 'smtp.username'),
"password" => data_get($notifiable, 'smtp.password'),
"password" => $password,
"timeout" => data_get($notifiable, 'smtp.timeout'),
"local_domain" => null,
]);

View File

@ -75,6 +75,9 @@ function is_transactional_emails_active()
function set_transanctional_email_settings()
{
$settings = InstanceSettings::get();
$password = data_get($settings, 'smtp.password');
if ($password) $password = decrypt($password);
config()->set('mail.default', 'smtp');
config()->set('mail.mailers.smtp', [
"transport" => "smtp",
@ -82,7 +85,7 @@ function set_transanctional_email_settings()
"port" => data_get($settings, 'smtp.port'),
"encryption" => data_get($settings, 'smtp.encryption'),
"username" => data_get($settings, 'smtp.username'),
"password" => data_get($settings, 'smtp.password'),
"password" => $password,
"timeout" => data_get($settings, 'smtp.timeout'),
"local_domain" => null,
]);