diff --git a/app/Classes/Settings/Misc.php b/app/Classes/Settings/Misc.php index 6a215aff..beaa3a44 100644 --- a/app/Classes/Settings/Misc.php +++ b/app/Classes/Settings/Misc.php @@ -5,9 +5,9 @@ namespace App\Classes\Settings; use App\Models\Settings; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Validator; + class Misc { public function __construct() @@ -15,8 +15,6 @@ class Misc return; } - - public function updateSettings(Request $request) { $validator = Validator::make($request->all(), [ @@ -31,6 +29,14 @@ class Misc 'recaptcha-site-key' => 'nullable|string', 'recaptcha-secret-key' => 'nullable|string', 'enable-recaptcha' => 'nullable|string', + 'mailservice' => 'nullable|string', + 'mailhost' => 'nullable|string', + 'mailport' => 'nullable|string', + 'mailusername' => 'nullable|string', + 'mailpassword' => 'nullable|string', + 'mailencryption' => 'nullable|string', + 'mailfromadress' => 'nullable|string', + 'mailfromname' => 'nullable|string', ]); if ($validator->fails()) { @@ -55,12 +61,17 @@ class Misc "SETTINGS::RECAPTCHA:SITE_KEY" => "recaptcha-site-key", "SETTINGS::RECAPTCHA:SECRET_KEY" => "recaptcha-secret-key", "SETTINGS::RECAPTCHA:ENABLED" => "enable-recaptcha", + "SETTINGS::MAIL:MAILER" => "mailservice", + "SETTINGS::MAIL:HOST" => "mailhost", + "SETTINGS::MAIL:PORT" => "mailport", + "SETTINGS::MAIL:USERNAME" => "mailusername", + "SETTINGS::MAIL:PASSWORD" => "mailpassword", + "SETTINGS::MAIL:ENCRYPTION" => "mailencryption", + "SETTINGS::MAIL:FROM_ADDRESS" => "mailfromadress", + "SETTINGS::MAIL:FROM_NAME" => "mailfromname", + ]; - Config::set('services.discord.client_id', $request->get("discord-client-id")); - Config::set('services.discord.client_secret', $request->get("discord-client-secret")); - - foreach ($values as $key => $value) { $param = $request->get($value); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index f8ac085a..c03ebd7d 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -16,9 +16,9 @@ class ProfileController extends Controller { return view('profile.index')->with([ 'user' => Auth::user(), - 'credits_reward_after_verify_discord' => Settings::getValueByKey('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD'), - 'force_email_verification' => Settings::getValueByKey('SETTINGS::USER:FORCE_EMAIL_VERIFICATION'), - 'force_discord_verification' => Settings::getValueByKey('SETTINGS::USER:FORCE_DISCORD_VERIFICATION'), + 'credits_reward_after_verify_discord' => config('SETTINGS::USER:CREDITS_REWARD_AFTER_VERIFY_DISCORD'), + 'force_email_verification' => config('SETTINGS::USER:FORCE_EMAIL_VERIFICATION'), + 'force_discord_verification' => config('SETTINGS::USER:FORCE_DISCORD_VERIFICATION'), ]); } @@ -34,15 +34,15 @@ class ProfileController extends Controller $user = User::findOrFail($id); //update password if necessary - if (!is_null($request->input('new_password'))){ + if (!is_null($request->input('new_password'))) { //validate password request $request->validate([ 'current_password' => [ - 'required' , + 'required', function ($attribute, $value, $fail) use ($user) { if (!Hash::check($value, $user->password)) { - $fail('The '.$attribute.' is invalid.'); + $fail('The ' . $attribute . ' is invalid.'); } }, ], @@ -58,13 +58,13 @@ class ProfileController extends Controller //validate request $request->validate([ - 'name' => 'required|min:4|max:30|alpha_num|unique:users,name,'.$id.',id', - 'email' => 'required|email|max:64|unique:users,email,'.$id.',id', + 'name' => 'required|min:4|max:30|alpha_num|unique:users,name,' . $id . ',id', + 'email' => 'required|email|max:64|unique:users,email,' . $id . ',id', 'avatar' => 'nullable' ]); //update avatar - if(!is_null($request->input('avatar'))){ + if (!is_null($request->input('avatar'))) { $avatar = json_decode($request->input('avatar')); if ($avatar->input->size > 3000000) abort(500); @@ -83,6 +83,6 @@ class ProfileController extends Controller 'email' => $request->input('email'), ]); - return redirect()->route('profile.index')->with('success' , __('Profile updated')); + return redirect()->route('profile.index')->with('success', __('Profile updated')); } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 0db41e3b..33df8145 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,7 +4,7 @@ namespace App\Providers; use App\Models\Settings; use Illuminate\Pagination\Paginator; -use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Validator; use Illuminate\Support\ServiceProvider; @@ -51,20 +51,58 @@ class AppServiceProvider extends ServiceProvider return $ok; }); - if (!App::runningInConsole()) { - // Set Discord-API Config - config(['services.discord.client_id' => Settings::getValueByKey('SETTINGS::DISCORD:CLIENT_ID')]); - config(['services.discord.client_secret' => Settings::getValueByKey('SETTINGS::DISCORD:CLIENT_SECRET')]); - // Set Recaptcha API Config - config(['recaptcha.api_site_key' => Settings::getValueByKey('SETTINGS::RECAPTCHA:SITE_KEY')]); - config(['recaptcha.api_secret_key' => Settings::getValueByKey('SETTINGS::RECAPTCHA:SECRET_KEY')]); - - // Set all configs from database - $settings = Settings::all(); - foreach ($settings as $setting) { - config([$setting->key => $setting->value]); - } + // TODO: Check if Installer Lockfile exists instead of "running in console" + $settings = Settings::all(); + // Set all configs from database + foreach ($settings as $setting) { + config([$setting->key => $setting->value]); } + + // Set Mail Config + //only update config if mail settings have changed in DB + if ( + config('mail.default') != config('SETTINGS:MAIL:MAILER') || + config('mail.mailers.smtp.host') != config('SETTINGS:MAIL:HOST') || + config('mail.mailers.smtp.port') != config('SETTINGS:MAIL:PORT') || + config('mail.mailers.smtp.username') != config('SETTINGS:MAIL:USERNAME') || + config('mail.mailers.smtp.password') != config('SETTINGS:MAIL:PASSWORD') || + config('mail.mailers.smtp.encryption') != config('SETTINGS:MAIL:ENCRYPTION') || + config('mail.from.address') != config('SETTINGS:MAIL:FROM_ADDRESS') || + config('mail.from.name') != config('SETTINGS:MAIL:FROM_NAME') + ) { + config(['mail.default' => config('SETTINGS::MAIL:MAILER')]); + config(['mail.mailers.smtp' => [ + 'transport' => 'smtp', + 'host' => config('SETTINGS::MAIL:HOST'), + 'port' => config('SETTINGS::MAIL:PORT'), + 'encryption' => config('SETTINGS::MAIL:ENCRYPTION'), + 'username' => config('SETTINGS::MAIL:USERNAME'), + 'password' => config('SETTINGS::MAIL:PASSWORD'), + 'timeout' => null, + 'auth_mode' => null, + ]]); + config(['mail.from' => ['address' => config('SETTINGS::MAIL:FROM_ADDRESS'), 'name' => config('SETTINGS::MAIL:FROM_NAME')]]); + + Artisan::call('queue:restart'); + } + + + // Set Recaptcha API Config + //only update config if recaptcha settings have changed in DB + if ( + config('recaptcha.api_site_key') != config('SETTINGS::RECAPTCHA:SITE_KEY') || + config('recaptcha.api_secret_key') != config('SETTINGS::RECAPTCHA:SECRET_KEY') + ) { + config(['recaptcha.api_site_key' => config('SETTINGS::RECAPTCHA:SITE_KEY')]); + config(['recaptcha.api_secret_key' => config('SETTINGS::RECAPTCHA:SECRET_KEY')]); + + Artisan::call('config:clear'); + Artisan::call('cache:clear'); + } + + // Set Discord-API Config + config(['services.discord.client_id' => config('SETTINGS::DISCORD:CLIENT_ID')]); + config(['services.discord.client_secret' => config('SETTINGS::DISCORD:CLIENT_SECRET')]); } } diff --git a/config/mail.php b/config/mail.php index 54299aab..3addd6aa 100644 --- a/config/mail.php +++ b/config/mail.php @@ -45,31 +45,22 @@ return [ 'auth_mode' => null, ], - 'ses' => [ - 'transport' => 'ses', - ], - - 'mailgun' => [ - 'transport' => 'mailgun', - ], - - 'postmark' => [ - 'transport' => 'postmark', - ], - - 'sendmail' => [ - 'transport' => 'sendmail', - 'path' => '/usr/sbin/sendmail -bs', - ], - - 'log' => [ - 'transport' => 'log', - 'channel' => env('MAIL_LOG_CHANNEL'), - ], - - 'array' => [ - 'transport' => 'array', - ], + // 'ses' => [ + // 'transport' => 'ses', + // ], + // + // 'mailgun' => [ + // 'transport' => 'mailgun', + // ], + // + // 'postmark' => [ + // 'transport' => 'postmark', + // ], + // + // 'sendmail' => [ + // 'transport' => 'sendmail', + // 'path' => '/usr/sbin/sendmail -bs', + // ], ], /* diff --git a/database/seeders/Seeds/SettingsSeeder.php b/database/seeders/Seeds/SettingsSeeder.php index b41462d6..19389f1d 100644 --- a/database/seeders/Seeds/SettingsSeeder.php +++ b/database/seeders/Seeds/SettingsSeeder.php @@ -405,6 +405,64 @@ class SettingsSeeder extends Seeder ], [ 'value' => 'true', 'type' => 'boolean', + 'description' => 'Enables or disables the ReCaptcha feature on the registration/login page' + + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:MAILER', + ], [ + 'value' => 'smtp', + 'type' => 'string', + 'description' => 'Selected Mailer (smtp, mailgun, sendgrid, mailtrap)' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:HOST', + ], [ + 'value' => 'localhost', + 'type' => 'string', + 'description' => 'Mailer Host Adress' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:PORT', + ], [ + 'value' => '1025', + 'type' => 'string', + 'description' => 'Mailer Server Port' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:USERNAME', + ], [ + 'value' => '', + 'type' => 'string', + 'description' => 'Mailer Username' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:PASSWORD', + ], [ + 'value' => '', + 'type' => 'string', + 'description' => 'Mailer Password' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:ENCRYPTION', + ], [ + 'value' => 'tls', + 'type' => 'string', + 'description' => 'Mailer Encryption (tls, ssl)' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:FROM_ADDRESS', + ], [ + 'value' => '', + 'type' => 'string', + 'description' => 'Mailer From Address' + ]); + Settings::firstOrCreate([ + 'key' => 'SETTINGS::MAIL:FROM_NAME', + ], [ + 'value' => env('APP_NAME', 'Controlpanel'), + 'type' => 'string', + 'description' => 'Mailer From Name' ]); } } diff --git a/resources/views/admin/settings/tabs/misc.blade.php b/resources/views/admin/settings/tabs/misc.blade.php index 623ef94b..6452881b 100644 --- a/resources/views/admin/settings/tabs/misc.blade.php +++ b/resources/views/admin/settings/tabs/misc.blade.php @@ -5,6 +5,86 @@ @method('PATCH')
+ + {{-- E-Mail --}} +
+
+
+

E-Mail

+
+
+ +
+ + +
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+
@@ -104,6 +184,8 @@
+ +