mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 14:26:58 +00:00
Send test message from admin.
This commit is contained in:
44
app/Events/AdminRequestedTestMessage.php
Normal file
44
app/Events/AdminRequestedTestMessage.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* AdminRequestedTestMessage.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Events;
|
||||
|
||||
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class AdminRequestedTestMessage
|
||||
*
|
||||
* @package FireflyIII\Events
|
||||
*/
|
||||
class AdminRequestedTestMessage extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
public $ipAddress;
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param User $user
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(User $user, string $ipAddress)
|
||||
{
|
||||
Log::debug(sprintf('Triggered AdminRequestedTestMessage for user #%d (%s) and IP %s!', $user->id, $user->email, $ipAddress));
|
||||
$this->user = $user;
|
||||
$this->ipAddress = $ipAddress;
|
||||
}
|
||||
}
|
55
app/Handlers/Events/AdminEventHandler.php
Normal file
55
app/Handlers/Events/AdminEventHandler.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* AdminEventHandler.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Handlers\Events;
|
||||
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Mail\AdminTestMail;
|
||||
use Log;
|
||||
use Mail;
|
||||
use Session;
|
||||
use Swift_TransportException;
|
||||
|
||||
/**
|
||||
* Class AdminEventHandler
|
||||
*
|
||||
* @package FireflyIII\Handlers\Events
|
||||
*/
|
||||
class AdminEventHandler
|
||||
{
|
||||
/**
|
||||
* @param AdminRequestedTestMessage $event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendTestMessage(AdminRequestedTestMessage $event): bool
|
||||
{
|
||||
|
||||
$email = $event->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;
|
||||
}
|
||||
}
|
@@ -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'));
|
||||
}
|
||||
|
||||
}
|
||||
|
53
app/Mail/AdminTestMail.php
Normal file
53
app/Mail/AdminTestMail.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* AdminTestMail.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Mail;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class AdminTestMail
|
||||
*
|
||||
* @package FireflyIII\Mail
|
||||
*/
|
||||
class AdminTestMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
/** @var string */
|
||||
public $email;
|
||||
/** @var string */
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* ConfirmEmailChangeMail constructor.
|
||||
*
|
||||
* @param string $email
|
||||
* @param string $ipAddress
|
||||
*/
|
||||
public function __construct(string $email, string $ipAddress)
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
@@ -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' =>
|
||||
[
|
||||
|
@@ -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 <a href="/admin">Administration</a>.',
|
||||
'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 <a href="/admin">Administration</a>.',
|
||||
'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), <strong>the log files will reflect any errors</strong>. You can press this button as many times as you like. There is no spam control. The message will be sent to <code>:email</code> 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',
|
||||
|
@@ -18,6 +18,28 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6 col-md-12 col-sm-12 col-xs-12">
|
||||
<div class="box box-default">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'send_test_email'|_ }}</h3>
|
||||
</div>
|
||||
<form action="{{ route('admin.test-message') }}" method="post">
|
||||
<div class="box-body">
|
||||
<p>
|
||||
{{ trans('firefly.send_test_email_text', {email:Auth.user.email})|raw }}
|
||||
</p>
|
||||
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn btn-success">
|
||||
<i class="fa fa-envelope"></i> {{ ('send_message')|_ }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
5
resources/views/emails/admin-test-html.twig
Normal file
5
resources/views/emails/admin-test-html.twig
Normal file
@@ -0,0 +1,5 @@
|
||||
{% include 'emails.header-html' %}
|
||||
<p style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;">
|
||||
This is a test message from your Firefly III instance. It was sent to {{ email }}.
|
||||
</p>
|
||||
{% include 'emails.footer-html' %}
|
3
resources/views/emails/admin-test-text.twig
Normal file
3
resources/views/emails/admin-test-text.twig
Normal file
@@ -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' %}
|
@@ -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']);
|
||||
|
Reference in New Issue
Block a user