diff --git a/app/Events/AdminRequestedTestMessage.php b/app/Events/AdminRequestedTestMessage.php new file mode 100644 index 0000000000..ce783fc8ef --- /dev/null +++ b/app/Events/AdminRequestedTestMessage.php @@ -0,0 +1,44 @@ +id, $user->email, $ipAddress)); + $this->user = $user; + $this->ipAddress = $ipAddress; + } +} diff --git a/app/Handlers/Events/AdminEventHandler.php b/app/Handlers/Events/AdminEventHandler.php new file mode 100644 index 0000000000..55b83abadf --- /dev/null +++ b/app/Handlers/Events/AdminEventHandler.php @@ -0,0 +1,55 @@ +user->email; + $ipAddress = $event->ipAddress; + + Log::debug(sprintf('Now in sendTestMessage event handler. Email is %s, IP is %s', $email, $ipAddress)); + try { + Log::debug('Trying to send message...'); + Mail::to($email)->send(new AdminTestMail($email, $ipAddress)); + // @codeCoverageIgnoreStart + } catch (Swift_TransportException $e) { + Log::debug('Send message failed! :('); + Log::error($e->getMessage()); + Log::error($e->getTraceAsString()); + Session::flash('error', 'Possible email error: ' . $e->getMessage()); + } + Log::debug('If no error above this line, message was sent.'); + // @codeCoverageIgnoreEnd + return true; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/HomeController.php b/app/Http/Controllers/Admin/HomeController.php index 6cc7090a62..66da4a214c 100644 --- a/app/Http/Controllers/Admin/HomeController.php +++ b/app/Http/Controllers/Admin/HomeController.php @@ -14,7 +14,11 @@ declare(strict_types=1); namespace FireflyIII\Http\Controllers\Admin; +use FireflyIII\Events\AdminRequestedTestMessage; use FireflyIII\Http\Controllers\Controller; +use Illuminate\Http\Request; +use Session; +use Log; /** * Class HomeController @@ -34,4 +38,18 @@ class HomeController extends Controller return view('admin.index', compact('title', 'mainTitleIcon')); } + /** + * @param Request $request + * + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function testMessage(Request $request) + { + $ipAddress = $request->ip(); + Log::debug(sprintf('Now in testMessage() controller. IP is %s', $ipAddress)); + event(new AdminRequestedTestMessage(auth()->user(), $ipAddress)); + Session::flash('info', strval(trans('firefly.send_test_triggered'))); + return redirect(route('admin.index')); + } + } diff --git a/app/Mail/AdminTestMail.php b/app/Mail/AdminTestMail.php new file mode 100644 index 0000000000..b75495ff9e --- /dev/null +++ b/app/Mail/AdminTestMail.php @@ -0,0 +1,53 @@ +email = $email; + $this->ipAddress = $ipAddress; + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->view('emails.admin-test-html')->text('emails.admin-test-text') + ->subject('A test message from your Firefly III installation'); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 4e7aa2068b..943e879183 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -51,6 +51,10 @@ class EventServiceProvider extends ServiceProvider 'FireflyIII\Handlers\Events\UserEventHandler@sendEmailChangeConfirmMail', 'FireflyIII\Handlers\Events\UserEventHandler@sendEmailChangeUndoMail', ], + // admin related + 'FireflyIII\Events\AdminRequestedTestMessage' => [ + 'FireflyIII\Handlers\Events\AdminEventHandler@sendTestMessage', + ], // is a Transaction Journal related event. 'FireflyIII\Events\StoredTransactionJournal' => [ diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php index 964414594a..d610a122c6 100644 --- a/resources/lang/en_US/firefly.php +++ b/resources/lang/en_US/firefly.php @@ -425,7 +425,7 @@ return [ 'regenerate_access_token' => 'Regenerate access token', 'token_regenerated' => 'A new token was generated', 'change_your_email' => 'Change your email address', - 'email_verification' => 'An email message will be sent to your old AND new email address. For security purposes, you will not be able to login until you verify your new email address. If you are unsure if your Firefly III installation is capable of sending email, please do not use this feature. You can test this in the Administration.', + 'email_verification' => 'An email message will be sent to your old AND new email address. For security purposes, you will not be able to login until you verify your new email address. If you are unsure if your Firefly III installation is capable of sending email, please do not use this feature. If you are an administrator, you can test this in the Administration.', 'email_changed_logout' => 'Until you verify your email address, you cannot login.', 'login_with_new_email' => 'You can now login with your new email address.', 'login_with_old_email' => 'You can now login with your old email address again.', @@ -907,6 +907,10 @@ return [ 'updated_user' => 'User data has been changed.', 'delete_user' => 'Delete user :email', 'user_deleted' => 'The user has been deleted', + 'send_test_email' => 'Send test email message', + 'send_test_email_text' => 'To see if your installation is capable of sending email, please press this button. You will not see an error here (if any), the log files will reflect any errors. You can press this button as many times as you like. There is no spam control. The message will be sent to :email and should arrive shortly.', + 'send_message' => 'Send message', + 'send_test_triggered' => 'Test was triggered. Check your inbox and the log files.', // links 'journal_link_configuration' => 'Transaction links configuration', diff --git a/resources/views/admin/index.twig b/resources/views/admin/index.twig index 1de89abcc3..a12c21d151 100644 --- a/resources/views/admin/index.twig +++ b/resources/views/admin/index.twig @@ -18,6 +18,28 @@ + +
+
+
+

{{ 'send_test_email'|_ }}

+
+
+
+

+ {{ trans('firefly.send_test_email_text', {email:Auth.user.email})|raw }} +

+ + +
+ +
+
+
diff --git a/resources/views/emails/admin-test-html.twig b/resources/views/emails/admin-test-html.twig new file mode 100644 index 0000000000..0862786993 --- /dev/null +++ b/resources/views/emails/admin-test-html.twig @@ -0,0 +1,5 @@ +{% include 'emails.header-html' %} +

+ This is a test message from your Firefly III instance. It was sent to {{ email }}. +

+{% include 'emails.footer-html' %} diff --git a/resources/views/emails/admin-test-text.twig b/resources/views/emails/admin-test-text.twig new file mode 100644 index 0000000000..23c246e694 --- /dev/null +++ b/resources/views/emails/admin-test-text.twig @@ -0,0 +1,3 @@ +{% include 'emails.header-text' %} + This is a test message from your Firefly III instance. It was sent to {{ email }}. +{% include 'emails.footer-text' %} diff --git a/routes/web.php b/routes/web.php index a6cbcdfc63..026774b8b5 100755 --- a/routes/web.php +++ b/routes/web.php @@ -777,6 +777,7 @@ Route::group( // admin home Route::get('', ['uses' => 'HomeController@index', 'as' => 'index']); + Route::post('test-message', ['uses' => 'HomeController@testMessage', 'as' => 'test-message']); // user manager Route::get('users', ['uses' => 'UserController@index', 'as' => 'users']);