From cd193ce8bba01e9587d8c278aee3026f2467ce11 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 19 Oct 2017 08:18:56 -0700 Subject: [PATCH] Fixes #4036 - adds test email button to general settings --- .../Controllers/Api/SettingsController.php | 25 ++++++ app/Http/Controllers/SettingsController.php | 5 +- resources/views/settings/general.blade.php | 12 ++- resources/views/setup/index.blade.php | 86 +++++++++++++------ routes/api.php | 10 ++- 5 files changed, 107 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 6cc6724e09..f8ba5942bd 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Models\Ldap; use Validator; use App\Models\Setting; +use Mail; class SettingsController extends Controller { @@ -160,4 +161,28 @@ class SettingsController extends Controller } + /** + * Test the email configuration + * + * @author [A. Gianotto] [] + * @since [v3.0] + * @return Redirect + */ + public function ajaxTestEmail() + { + try { + Mail::send('emails.test', [], function ($m) { + $m->to(config('mail.from.address'), config('mail.from.name')); + $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); + $m->subject(trans('mail.test_email')); + }); + return response()->json(['message' => 'Mail sent! '], 200); + } catch (Exception $e) { + return response()->json(['message' => $e->getMessage()], 500); + } + + } + + + } diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index a65dd3270a..2cbf5cd289 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -21,6 +21,7 @@ use App\Models\User; use App\Http\Requests\SetupUserRequest; use App\Http\Requests\ImageUploadRequest; use App\Http\Requests\SettingsLdapRequest; +use App\Helpers\Helper; /** * This controller handles all actions related to Settings for @@ -1020,9 +1021,9 @@ class SettingsController extends Controller $m->replyTo(config('mail.reply_to.address'), config('mail.reply_to.name')); $m->subject(trans('mail.test_email')); }); - return response()->json(['message' => 'Mail sent! '], 200); + return response()->json(Helper::formatStandardApiResponse('success', null, 'Maiol sent!')); } catch (Exception $e) { - return response()->json(['message' => $e->getMessage()], 500); + return response()->json(Helper::formatStandardApiResponse('success', null, $e->getMessage())); } } diff --git a/resources/views/settings/general.blade.php b/resources/views/settings/general.blade.php index d33691b84a..ffa7ad9548 100644 --- a/resources/views/settings/general.blade.php +++ b/resources/views/settings/general.blade.php @@ -194,7 +194,7 @@
-

This will attempt to send a test mail to {{ config('mail.reply_to.address') }}.

+

This will attempt to send a test mail to {{ config('mail.from.address') }}.

@@ -235,10 +235,12 @@ $("#mailtest").click(function(){ $("#mailtestrow").removeClass('text-success'); $("#mailtestrow").removeClass('text-danger'); + $("#mailtesticon").html(''); $("#mailteststatus").html(''); + $('#mailteststatus-error').html(''); $("#mailtesticon").html(' Sending Test Email...'); $.ajax({ - url: '{{ route('settings.mailtest') }}', + url: '{{ route('api.settings.mailtest') }}', type: 'POST', headers: { "X-Requested-With": 'XMLHttpRequest', @@ -265,7 +267,11 @@ $("#mailteststatus").addClass('text-danger'); $("#mailtesticon").html(''); $('#mailteststatus').html('Mail could not be sent.'); - $('#mailteststatus-error').html('Error: ' + data.responseJSON.messages); + if (data.responseJSON) { + $('#mailteststatus-error').html('Error: ' + data.responseJSON.messages); + } else { + console.dir(data); + } } diff --git a/resources/views/setup/index.blade.php b/resources/views/setup/index.blade.php index 602b272758..033d2da058 100644 --- a/resources/views/setup/index.blade.php +++ b/resources/views/setup/index.blade.php @@ -165,13 +165,22 @@ Create a User :: - + Email - + + + Send Test - - - + + + + +
+
+
+
+

This will attempt to send a test mail to {{ config('mail.from.address') }}.

+
@@ -190,34 +199,61 @@ Create a User :: @stop diff --git a/routes/api.php b/routes/api.php index fe0f5f3250..db12229776 100644 --- a/routes/api.php +++ b/routes/api.php @@ -428,7 +428,15 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () { 'as' => 'api.settings.ldaptestlogin', 'uses' => 'SettingsController@ldaptestlogin' ]); - + + Route::post( + 'settings/mailtest', + [ + 'as' => 'api.settings.mailtest', + 'uses' => 'SettingsController@ajaxTestEmail' ] + ); + + Route::resource('settings', 'SettingsController', [ 'names' =>