diff --git a/app/Classes/PterodactylClient.php b/app/Classes/PterodactylClient.php index d196c26c..a94fca74 100644 --- a/app/Classes/PterodactylClient.php +++ b/app/Classes/PterodactylClient.php @@ -12,6 +12,7 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; use App\Settings\PterodactylSettings; +use App\Settings\ServerSettings; class PterodactylClient { @@ -27,11 +28,13 @@ class PterodactylClient public function __construct(PterodactylSettings $ptero_settings) { + $server_settings = new ServerSettings(); + try { $this->client = $this->client($ptero_settings); $this->client_admin = $this->clientAdmin($ptero_settings); $this->per_page_limit = $ptero_settings->per_page_limit; - $this->allocation_limit = $ptero_settings->allocation_limit; + $this->allocation_limit = $server_settings->allocation_limit; } catch (Exception $exception) { logger('Failed to construct Pterodactyl client, Settings table not available?', ['exception' => $exception]); diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 1366bcd5..eafc351d 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -256,7 +256,12 @@ class UserController extends Controller } $all = $data['all'] ?? false; $users = $all ? User::all() : User::whereIn('id', $data['users'])->get(); - Notification::send($users, new DynamicNotification($data['via'], $database, $mail)); + try { + Notification::send($users, new DynamicNotification($data['via'], $database, $mail)); + } + catch (Exception $e) { + return redirect()->route('admin.users.notifications')->with('error', __('The attempt to send the email failed with the error: ' . $e->getMessage())); + } return redirect()->route('admin.users.notifications')->with('success', __('Notification sent!')); } diff --git a/app/Http/Controllers/Api/NotificationController.php b/app/Http/Controllers/Api/NotificationController.php index 9ccc47af..127948e2 100644 --- a/app/Http/Controllers/Api/NotificationController.php +++ b/app/Http/Controllers/Api/NotificationController.php @@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Notification; use Illuminate\Support\HtmlString; use Illuminate\Validation\ValidationException; use Spatie\ValidationRules\Rules\Delimited; +use Exception; class NotificationController extends Controller { @@ -104,8 +105,12 @@ class NotificationController extends Controller 'users' => ['No users found!'], ]); } - - Notification::send($users, new DynamicNotification($via, $database, $mail)); + try { + Notification::send($users, new DynamicNotification($via, $database, $mail)); + } + catch (Exception $e) { + return response()->json(['message' => 'The attempt to send the email failed with the error: ' . $e->getMessage()], 500); + } return response()->json(['message' => 'Notification successfully sent.', 'user_count' => $users->count()]); } diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 35136f50..fc27b7b5 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -27,6 +27,22 @@ class RegisterController extends Controller { private $pterodactyl; + private $credits_display_name; + + private $recaptcha_enabled; + + private $website_show_tos; + + private $register_ip_check; + + private $initial_credits; + + private $initial_server_limit; + + private $referral_mode; + + private $referral_reward; + /* |-------------------------------------------------------------------------- | Register Controller @@ -52,10 +68,18 @@ class RegisterController extends Controller * * @return void */ - public function __construct(PterodactylSettings $ptero_settings) + public function __construct(PterodactylSettings $ptero_settings, GeneralSettings $general_settings, WebsiteSettings $website_settings, UserSettings $user_settings, ReferralSettings $referral_settings) { $this->middleware('guest'); $this->pterodactyl = new PterodactylClient($ptero_settings); + $this->credits_display_name = $general_settings->credits_display_name; + $this->recaptcha_enabled = $general_settings->recaptcha_enabled; + $this->website_show_tos = $website_settings->show_tos; + $this->register_ip_check = $user_settings->register_ip_check; + $this->initial_credits = $user_settings->initial_credits; + $this->initial_server_limit = $user_settings->initial_server_limit; + $this->referral_mode = $referral_settings->mode; + $this->referral_reward = $referral_settings->reward; } /** @@ -64,21 +88,21 @@ class RegisterController extends Controller * @param array $data * @return \Illuminate\Contracts\Validation\Validator */ - protected function validator(array $data, GeneralSettings $general_settings, WebsiteSettings $website_settings, UserSettings $user_settings) + protected function validator(array $data) { $validationRules = [ 'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'], 'email' => ['required', 'string', 'email', 'max:64', 'unique:users'], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]; - if ($general_settings->recaptcha_enabled) { + if ($this->recaptcha_enabled) { $validationRules['g-recaptcha-response'] = ['required', 'recaptcha']; } - if ($website_settings->show_tos) { + if ($this->website_show_tos) { $validationRules['terms'] = ['required']; } - if ($user_settings->register_ip_check) { + if ($this->register_ip_check) { //check if ip has already made an account $data['ip'] = session()->get('ip') ?? request()->ip(); @@ -102,13 +126,13 @@ class RegisterController extends Controller * @param array $data * @return User */ - protected function create(array $data, GeneralSettings $general_settings, UserSettings $user_settings, ReferralSettings $referral_settings) + protected function create(array $data) { $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], - 'credits' => $user_settings->initial_credits, - 'server_limit' => $user_settings->initial_server_limit, + 'credits' => $this->initial_credits, + 'server_limit' => $this->initial_server_limit, 'password' => Hash::make($data['password']), 'referral_code' => $this->createReferralCode(), @@ -142,15 +166,15 @@ class RegisterController extends Controller $ref_code = $data['referral_code']; $new_user = $user->id; if ($ref_user = User::query()->where('referral_code', '=', $ref_code)->first()) { - if ($referral_settings->mode === 'sign-up' || $referral_settings->mode === 'both') { - $ref_user->increment('credits', $referral_settings->reward); + if ($this->referral_mode === 'sign-up' || $this->referral_mode === 'both') { + $ref_user->increment('credits', $this->referral_reward); $ref_user->notify(new ReferralNotification($ref_user->id, $new_user)); //LOGS REFERRALS IN THE ACTIVITY LOG activity() ->performedOn($user) ->causedBy($ref_user) - ->log('gained ' . $referral_settings->reward . ' ' . $general_settings->credits_display_name . ' for sign-up-referral of ' . $user->name . ' (ID:' . $user->id . ')'); + ->log('gained ' . $this->referral_reward . ' ' . $this->credits_display_name . ' for sign-up-referral of ' . $user->name . ' (ID:' . $user->id . ')'); } //INSERT INTO USER_REFERRALS TABLE DB::table('user_referrals')->insert([ diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 88e4c3cd..c6018744 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -3,9 +3,9 @@ namespace App\Providers; use App\Models\UsefulLink; +use App\Settings\MailSettings; use Exception; use Illuminate\Pagination\Paginator; -use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Validator; @@ -62,6 +62,9 @@ class AppServiceProvider extends ServiceProvider Log::error("Couldnt find useful_links. Probably the installation is not completet. " . $e); } + $settings = $this->app->make(MailSettings::class); + $settings->setConfig(); + //only run if the installer has been executed // try { // $settings = Settings::all(); diff --git a/app/Settings/MailSettings.php b/app/Settings/MailSettings.php index 7505eb85..efee9bf0 100644 --- a/app/Settings/MailSettings.php +++ b/app/Settings/MailSettings.php @@ -6,23 +6,23 @@ use Spatie\LaravelSettings\Settings; class MailSettings extends Settings { - public string $mail_host; + public ?string $mail_host; - public int $mail_port; + public ?int $mail_port; - public string $mail_username; + public ?string $mail_username; - public string $mail_password; + public ?string $mail_password; - public string $mail_encryption; + public ?string $mail_encryption; - public string $mail_from_address; + public ?string $mail_from_address; - public string $mail_from_name; + public ?string $mail_from_name; - public string $mail_mailer; + public ?string $mail_mailer; - public bool $mail_enabled; + public ?bool $mail_enabled; public static function group(): string { @@ -35,4 +35,20 @@ class MailSettings extends Settings 'mail_password' ]; } + + public function setConfig() + { + try { + config()->set('mail.mailers.smtp.host', $this->mail_host); + config()->set('mail.mailers.smtp.port', $this->mail_port); + config()->set('mail.mailers.smtp.encryption', $this->mail_encryption); + config()->set('mail.mailers.smtp.username', $this->mail_username); + config()->set('mail.mailers.smtp.password', $this->mail_password); + config()->set('mail.from.address', $this->mail_from_address); + config()->set('mail.from.name', $this->mail_from_name); + config()->set('mail.mailers.smtp.transport', $this->mail_mailer); + } catch (\Exception) { + + } + } } \ No newline at end of file diff --git a/config/mail.php b/config/mail.php index 534395a3..2974614e 100644 --- a/config/mail.php +++ b/config/mail.php @@ -93,7 +93,7 @@ return [ 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), - 'name' => env('MAIL_FROM_NAME', 'Example'), + 'name' => env('MAIL_FROM_NAME', 'ControlPanel'), ], /*