Browse Source

Some things to be adjusted

Ferks-FK 2 years ago
parent
commit
49904b22bf

+ 4 - 1
app/Classes/PterodactylClient.php

@@ -12,6 +12,7 @@ use Illuminate\Http\Client\PendingRequest;
 use Illuminate\Http\Client\Response;
 use Illuminate\Http\Client\Response;
 use Illuminate\Support\Facades\Http;
 use Illuminate\Support\Facades\Http;
 use App\Settings\PterodactylSettings;
 use App\Settings\PterodactylSettings;
+use App\Settings\ServerSettings;
 
 
 class PterodactylClient
 class PterodactylClient
 {
 {
@@ -27,11 +28,13 @@ class PterodactylClient
     
     
     public function __construct(PterodactylSettings $ptero_settings)
     public function __construct(PterodactylSettings $ptero_settings)
     {
     {
+        $server_settings = new ServerSettings();
+        
         try {
         try {
             $this->client = $this->client($ptero_settings);
             $this->client = $this->client($ptero_settings);
             $this->client_admin = $this->clientAdmin($ptero_settings);
             $this->client_admin = $this->clientAdmin($ptero_settings);
             $this->per_page_limit = $ptero_settings->per_page_limit;
             $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) {
         catch (Exception $exception) {
             logger('Failed to construct Pterodactyl client, Settings table not available?', ['exception' => $exception]);
             logger('Failed to construct Pterodactyl client, Settings table not available?', ['exception' => $exception]);

+ 6 - 1
app/Http/Controllers/Admin/UserController.php

@@ -256,7 +256,12 @@ class UserController extends Controller
         }
         }
         $all = $data['all'] ?? false;
         $all = $data['all'] ?? false;
         $users = $all ? User::all() : User::whereIn('id', $data['users'])->get();
         $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!'));
         return redirect()->route('admin.users.notifications')->with('success', __('Notification sent!'));
     }
     }

+ 7 - 2
app/Http/Controllers/Api/NotificationController.php

@@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Notification;
 use Illuminate\Support\HtmlString;
 use Illuminate\Support\HtmlString;
 use Illuminate\Validation\ValidationException;
 use Illuminate\Validation\ValidationException;
 use Spatie\ValidationRules\Rules\Delimited;
 use Spatie\ValidationRules\Rules\Delimited;
+use Exception;
 
 
 class NotificationController extends Controller
 class NotificationController extends Controller
 {
 {
@@ -104,8 +105,12 @@ class NotificationController extends Controller
                 'users' => ['No users found!'],
                 '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()]);
         return response()->json(['message' => 'Notification successfully sent.', 'user_count' => $users->count()]);
     }
     }

+ 35 - 11
app/Http/Controllers/Auth/RegisterController.php

@@ -27,6 +27,22 @@ class RegisterController extends Controller
 {
 {
     private $pterodactyl;
     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
     | Register Controller
@@ -52,10 +68,18 @@ class RegisterController extends Controller
      *
      *
      * @return void
      * @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->middleware('guest');
         $this->pterodactyl = new PterodactylClient($ptero_settings);
         $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
      * @param  array  $data
      * @return \Illuminate\Contracts\Validation\Validator
      * @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 = [
         $validationRules = [
             'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'],
             'name' => ['required', 'string', 'max:30', 'min:4', 'alpha_num', 'unique:users'],
             'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
             'email' => ['required', 'string', 'email', 'max:64', 'unique:users'],
             'password' => ['required', 'string', 'min:8', 'confirmed'],
             'password' => ['required', 'string', 'min:8', 'confirmed'],
         ];
         ];
-        if ($general_settings->recaptcha_enabled) {
+        if ($this->recaptcha_enabled) {
             $validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
             $validationRules['g-recaptcha-response'] = ['required', 'recaptcha'];
         }
         }
-        if ($website_settings->show_tos) {
+        if ($this->website_show_tos) {
             $validationRules['terms'] = ['required'];
             $validationRules['terms'] = ['required'];
         }
         }
 
 
-        if ($user_settings->register_ip_check) {
+        if ($this->register_ip_check) {
 
 
             //check if ip has already made an account
             //check if ip has already made an account
             $data['ip'] = session()->get('ip') ?? request()->ip();
             $data['ip'] = session()->get('ip') ?? request()->ip();
@@ -102,13 +126,13 @@ class RegisterController extends Controller
      * @param  array  $data
      * @param  array  $data
      * @return User
      * @return User
      */
      */
-    protected function create(array $data, GeneralSettings $general_settings, UserSettings $user_settings, ReferralSettings $referral_settings)
+    protected function create(array $data)
     {
     {
         $user = User::create([
         $user = User::create([
             'name' => $data['name'],
             'name' => $data['name'],
             'email' => $data['email'],
             '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']),
             'password' => Hash::make($data['password']),
             'referral_code' => $this->createReferralCode(),
             'referral_code' => $this->createReferralCode(),
 
 
@@ -142,15 +166,15 @@ class RegisterController extends Controller
             $ref_code = $data['referral_code'];
             $ref_code = $data['referral_code'];
             $new_user = $user->id;
             $new_user = $user->id;
             if ($ref_user = User::query()->where('referral_code', '=', $ref_code)->first()) {
             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));
                     $ref_user->notify(new ReferralNotification($ref_user->id, $new_user));
 
 
                     //LOGS REFERRALS IN THE ACTIVITY LOG
                     //LOGS REFERRALS IN THE ACTIVITY LOG
                     activity()
                     activity()
                         ->performedOn($user)
                         ->performedOn($user)
                         ->causedBy($ref_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
                 //INSERT INTO USER_REFERRALS TABLE
                 DB::table('user_referrals')->insert([
                 DB::table('user_referrals')->insert([

+ 4 - 1
app/Providers/AppServiceProvider.php

@@ -3,9 +3,9 @@
 namespace App\Providers;
 namespace App\Providers;
 
 
 use App\Models\UsefulLink;
 use App\Models\UsefulLink;
+use App\Settings\MailSettings;
 use Exception;
 use Exception;
 use Illuminate\Pagination\Paginator;
 use Illuminate\Pagination\Paginator;
-use Illuminate\Support\Facades\Artisan;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\Facades\Validator;
 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);
             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
         //only run if the installer has been executed
         // try {
         // try {
         //     $settings = Settings::all();
         //     $settings = Settings::all();

+ 25 - 9
app/Settings/MailSettings.php

@@ -6,23 +6,23 @@ use Spatie\LaravelSettings\Settings;
 
 
 class MailSettings extends 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
     public static function group(): string
     {
     {
@@ -35,4 +35,20 @@ class MailSettings extends Settings
             'mail_password'
             '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) {
+
+        }
+    }
 }
 }

+ 1 - 1
config/mail.php

@@ -93,7 +93,7 @@ return [
 
 
     'from' => [
     'from' => [
         'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
         'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
-        'name' => env('MAIL_FROM_NAME', 'Example'),
+        'name' => env('MAIL_FROM_NAME', 'ControlPanel'),
     ],
     ],
 
 
     /*
     /*