Browse Source

Added REGISTER_IP_CHECK config option

Prevent users from making multiple accounts using the same IP address
AVMG20 4 years ago
parent
commit
823cde9cf9

+ 2 - 2
.env.example

@@ -36,8 +36,8 @@ PHPMYADMIN_URL=https://mysql.bitsec.dev
 DISCORD_INVITE_URL=https://discord.gg/vrUYdxG4wZ
 DISCORD_INVITE_URL=https://discord.gg/vrUYdxG4wZ
 
 
 #GOOGLE RECAPTCHA
 #GOOGLE RECAPTCHA
-RECAPTCHA_SITE_KEY=YOUR_API_SITE_KEY
-RECAPTCHA_SECRET_KEY=YOUR_API_SECRET_KEY
+RECAPTCHA_SITE_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
+RECAPTCHA_SECRET_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
 
 
 MAIL_MAILER=smtp
 MAIL_MAILER=smtp
 MAIL_HOST=mailhog
 MAIL_HOST=mailhog

+ 23 - 12
app/Http/Controllers/Auth/RegisterController.php

@@ -8,9 +8,10 @@ use App\Models\Configuration;
 use App\Models\User;
 use App\Models\User;
 use App\Providers\RouteServiceProvider;
 use App\Providers\RouteServiceProvider;
 use Illuminate\Foundation\Auth\RegistersUsers;
 use Illuminate\Foundation\Auth\RegistersUsers;
+use Illuminate\Support\Facades\App;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
 use Illuminate\Support\Facades\Validator;
-use Illuminate\Validation\ValidationException;
+use Illuminate\Support\Str;
 
 
 class RegisterController extends Controller
 class RegisterController extends Controller
 {
 {
@@ -52,39 +53,50 @@ class RegisterController extends Controller
      */
      */
     protected function validator(array $data)
     protected function validator(array $data)
     {
     {
-        //check if ip has already made an account
-        $data['ip'] = session()->get('ip') ?? request()->ip();
-        if (User::where('ip', '=', request()->ip())->exists()) session()->put('ip', request()->ip());
+        if (Configuration::getValueByKey('REGISTER_IP_CHECK', 'true') == 'true') {
+
+            //check if ip has already made an account
+            $data['ip'] = session()->get('ip') ?? request()->ip();
+            if (User::where('ip', '=', request()->ip())->exists()) session()->put('ip', request()->ip());
+
+            return Validator::make($data, [
+                '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'],
+                'g-recaptcha-response' => ['recaptcha'],
+                'ip'                   => ['unique:users'],
+            ], [
+                'ip.unique' => "You have already made an account with us! Please contact support if you think this is incorrect."
+            ]);
+        }
 
 
         return Validator::make($data, [
         return Validator::make($data, [
             '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'],
             'g-recaptcha-response' => ['recaptcha'],
             'g-recaptcha-response' => ['recaptcha'],
-            'ip'                   => ['unique:users'],
-        ], [
-            'ip.unique'  => "You have already made an account with us! Please contact support if you think this is incorrect."
         ]);
         ]);
+
     }
     }
 
 
     /**
     /**
      * Create a new user instance after a valid registration.
      * Create a new user instance after a valid registration.
      *
      *
      * @param array $data
      * @param array $data
-     * @return User|\Illuminate\Http\RedirectResponse
+     * @return User
      */
      */
     protected function create(array $data)
     protected function create(array $data)
     {
     {
         $user = User::create([
         $user = User::create([
             'name'         => $data['name'],
             'name'         => $data['name'],
             'email'        => $data['email'],
             'email'        => $data['email'],
-            'credits'      => Configuration::getValueByKey('INITIAL_CREDITS'),
-            'server_limit' => Configuration::getValueByKey('INITIAL_SERVER_LIMIT'),
+            'credits'      => Configuration::getValueByKey('INITIAL_CREDITS', 150),
+            'server_limit' => Configuration::getValueByKey('INITIAL_SERVER_LIMIT', 1),
             'password'     => Hash::make($data['password']),
             'password'     => Hash::make($data['password']),
         ]);
         ]);
 
 
         $response = Pterodactyl::client()->post('/application/users', [
         $response = Pterodactyl::client()->post('/application/users', [
-            "external_id" => (string)$user->id,
+            "external_id" => App::environment('local') ? Str::random(16) : (string)$user->id,
             "username"    => $user->name,
             "username"    => $user->name,
             "email"       => $user->email,
             "email"       => $user->email,
             "first_name"  => $user->name,
             "first_name"  => $user->name,
@@ -96,7 +108,6 @@ class RegisterController extends Controller
 
 
         if ($response->failed()) {
         if ($response->failed()) {
             $user->delete();
             $user->delete();
-            redirect()->route('register')->with('error', 'pterodactyl error');
             return $user;
             return $user;
         }
         }
 
 

+ 37 - 26
database/seeders/Seeds/ConfigurationSeeder.php

@@ -18,16 +18,16 @@ class ConfigurationSeeder extends Seeder
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'INITIAL_CREDITS',
             'key' => 'INITIAL_CREDITS',
         ], [
         ], [
-            'value' => '250',
-            'type'  => 'integer',
+            'value'       => '250',
+            'type'        => 'integer',
             'description' => 'The initial amount of credits the user starts with.'
             'description' => 'The initial amount of credits the user starts with.'
         ]);
         ]);
 
 
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'INITIAL_SERVER_LIMIT',
             'key' => 'INITIAL_SERVER_LIMIT',
         ], [
         ], [
-            'value' => '1',
-            'type'  => 'integer',
+            'value'       => '1',
+            'type'        => 'integer',
             'description' => 'The initial server limit the user starts with.'
             'description' => 'The initial server limit the user starts with.'
         ]);
         ]);
 
 
@@ -35,33 +35,33 @@ class ConfigurationSeeder extends Seeder
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'CREDITS_REWARD_AFTER_VERIFY_EMAIL',
             'key' => 'CREDITS_REWARD_AFTER_VERIFY_EMAIL',
         ], [
         ], [
-            'value' => '250',
-            'type'  => 'integer',
+            'value'       => '250',
+            'type'        => 'integer',
             'description' => 'Increase in credits after the user has verified their email account.'
             'description' => 'Increase in credits after the user has verified their email account.'
         ]);
         ]);
 
 
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL',
             'key' => 'SERVER_LIMIT_REWARD_AFTER_VERIFY_EMAIL',
         ], [
         ], [
-            'value' => '2',
-            'type'  => 'integer',
+            'value'       => '2',
+            'type'        => 'integer',
             'description' => 'Increase in server limit after the user has verified their email account.'
             'description' => 'Increase in server limit after the user has verified their email account.'
         ]);
         ]);
 
 
         //verify discord event
         //verify discord event
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
-            'key'   => 'CREDITS_REWARD_AFTER_VERIFY_DISCORD',
-        ] , [
-            'value' => '375',
-            'type'  => 'integer',
+            'key' => 'CREDITS_REWARD_AFTER_VERIFY_DISCORD',
+        ], [
+            'value'       => '375',
+            'type'        => 'integer',
             'description' => 'Increase in credits after the user has verified their discord account.'
             'description' => 'Increase in credits after the user has verified their discord account.'
         ]);
         ]);
 
 
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD',
             'key' => 'SERVER_LIMIT_REWARD_AFTER_VERIFY_DISCORD',
         ], [
         ], [
-            'value' => '2',
-            'type'  => 'integer',
+            'value'       => '2',
+            'type'        => 'integer',
             'description' => 'Increase in server limit after the user has verified their discord account.'
             'description' => 'Increase in server limit after the user has verified their discord account.'
         ]);
         ]);
 
 
@@ -69,8 +69,8 @@ class ConfigurationSeeder extends Seeder
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER',
             'key' => 'MINIMUM_REQUIRED_CREDITS_TO_MAKE_SERVER',
         ], [
         ], [
-            'value' => '50',
-            'type'  => 'integer',
+            'value'       => '50',
+            'type'        => 'integer',
             'description' => 'The minimum amount of credits the user would need to make a server.'
             'description' => 'The minimum amount of credits the user would need to make a server.'
         ]);
         ]);
 
 
@@ -78,25 +78,36 @@ class ConfigurationSeeder extends Seeder
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
             'key' => 'SERVER_LIMIT_AFTER_IRL_PURCHASE',
             'key' => 'SERVER_LIMIT_AFTER_IRL_PURCHASE',
         ], [
         ], [
-            'value' => '10',
-            'type'  => 'integer',
+            'value'       => '10',
+            'type'        => 'integer',
             'description' => 'updates the users server limit to this amount (unless the user already has a higher server limit) after making a purchase with real money, set to 0 to ignore this.',
             'description' => 'updates the users server limit to this amount (unless the user already has a higher server limit) after making a purchase with real money, set to 0 to ignore this.',
         ]);
         ]);
 
 
+
+        //force email and discord verification
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
-            'key'   => 'FORCE_EMAIL_VERIFICATION',
-        ] , [
-            'value' => 'false',
-            'type'  => 'boolean',
+            'key' => 'FORCE_EMAIL_VERIFICATION',
+        ], [
+            'value'       => 'false',
+            'type'        => 'boolean',
             'description' => 'Force an user to verify the email adress before creating a server / buying credits.'
             'description' => 'Force an user to verify the email adress before creating a server / buying credits.'
         ]);
         ]);
 
 
         Configuration::firstOrCreate([
         Configuration::firstOrCreate([
-            'key'   => 'FORCE_DISCORD_VERIFICATION',
-        ] , [
-            'value' => 'false',
-            'type'  => 'boolean',
+            'key' => 'FORCE_DISCORD_VERIFICATION',
+        ], [
+            'value'       => 'false',
+            'type'        => 'boolean',
             'description' => 'Force an user to link an Discord Account before creating a server / buying credits.'
             'description' => 'Force an user to link an Discord Account before creating a server / buying credits.'
         ]);
         ]);
+
+        //disable ip check on register
+        Configuration::firstOrCreate([
+            'key' => 'REGISTER_IP_CHECK',
+        ], [
+            'value'       => 'true',
+            'type'        => 'boolean',
+            'description' => 'Prevent users from making multiple accounts using the same IP address'
+        ]);
     }
     }
 }
 }