From 811e56178b9a4345ead460ac05cba9a759b1a607 Mon Sep 17 00:00:00 2001 From: Julian Prieber Date: Mon, 13 Mar 2023 19:49:30 +0100 Subject: [PATCH] Added option to test SMTP setup --- app/Http/Controllers/AdminController.php | 18 ++++++++++++++++++ resources/views/auth/test.blade.php | 6 ++++++ .../views/components/config/config.blade.php | 14 ++++++++++++++ routes/web.php | 1 + 4 files changed, 39 insertions(+) create mode 100644 resources/views/auth/test.blade.php diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 1231991..d3586d7 100755 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Auth\Events\Registered; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Mail; use GeoSot\EnvEditor\Controllers\EnvController; use GeoSot\EnvEditor\Exceptions\EnvException; @@ -92,6 +93,23 @@ public function users(Request $request) return view('panel/users', $data); } +// Send test mail +public function SendTestMail(Request $request) +{ + try { + $userId = auth()->id(); + $user = User::findOrFail($userId); + + Mail::send('auth.test', ['user' => $user], function ($message) use ($user) { + $message->to($user->email) + ->subject('Test Email'); + }); + + return redirect()->route('showConfig')->with('success', 'Test email sent successfully!'); + } catch (\Exception $e) { + return redirect()->route('showConfig')->with('fail', 'Failed to send test email. Please try again later.'); + } +} //Block user public function blockUser(request $request) diff --git a/resources/views/auth/test.blade.php b/resources/views/auth/test.blade.php new file mode 100644 index 0000000..852934a --- /dev/null +++ b/resources/views/auth/test.blade.php @@ -0,0 +1,6 @@ + +
+ {{ __('Test E-Mail') }} +
+

+
diff --git a/resources/views/components/config/config.blade.php b/resources/views/components/config/config.blade.php index 4cf09bb..c24ead3 100644 --- a/resources/views/components/config/config.blade.php +++ b/resources/views/components/config/config.blade.php @@ -380,6 +380,20 @@ document.getElementById("MAINTENANCE_MODE-form").addEventListener("change", func + +
+

Test E-Mail setup:
+ @if (session('success')) +
+ {{ session('success') }} +
+@elseif (session('fail')) +
+ {{ session('fail') }} +
+@endif +
+ {{-- end SMTP settings --}} diff --git a/routes/web.php b/routes/web.php index e6eddc9..eeb42c5 100755 --- a/routes/web.php +++ b/routes/web.php @@ -173,6 +173,7 @@ Route::group([ Route::get('/update/theme', [AdminController::class, 'updateThemes'])->name('updateThemes'); Route::get('/panel/config', [AdminController::class, 'showConfig'])->name('showConfig'); Route::post('/panel/config', [AdminController::class, 'editConfig'])->name('editConfig'); + Route::get('/send-test-email', [AdminController::class, 'SendTestMail'])->name('SendTestMail'); Route::get('/theme-updater', function () {return view('studio/theme-updater', []);}); Route::get('/update', function () {return view('update', []);}); Route::get('/backup', function () {return view('backup', []);});