diff --git a/app/Http/Livewire/Notifications/EmailSettings.php b/app/Http/Livewire/Notifications/EmailSettings.php index ed39ad976..ded3c23dd 100644 --- a/app/Http/Livewire/Notifications/EmailSettings.php +++ b/app/Http/Livewire/Notifications/EmailSettings.php @@ -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 @@ class EmailSettings extends Component { $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(); diff --git a/app/Http/Livewire/Settings/Email.php b/app/Http/Livewire/Settings/Email.php index e15c9e5d6..dd6a31fa7 100644 --- a/app/Http/Livewire/Settings/Email.php +++ b/app/Http/Livewire/Settings/Email.php @@ -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 @@ class Email extends Component 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(); } } diff --git a/app/Notifications/Channels/EmailChannel.php b/app/Notifications/Channels/EmailChannel.php index bc5c7e46e..20c641b5d 100644 --- a/app/Notifications/Channels/EmailChannel.php +++ b/app/Notifications/Channels/EmailChannel.php @@ -35,6 +35,9 @@ class EmailChannel 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 @@ class EmailChannel "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, ]); diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 5d1821855..42359becd 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -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, ]);