diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index a9dff70..6b77d27 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -28,6 +28,7 @@ use App\User; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; +use Session; class RegisterController extends Controller { @@ -71,6 +72,10 @@ class RegisterController extends Controller { $password = ['required', 'string', 'confirmed']; + $signupEnabled = Options::getOption('enable_registrations'); + $signupOverride = Session::has('ALLOW_REGISTRATION_OVERRIDE') && Session::get('ALLOW_REGISTRATION_OVERRIDE') === true; + $signupOverrideEmail = Session::has('REGISTRATION_OVERRIDE_EMAIL') ? Session::get('REGISTRATION_OVERRIDE_EMAIL') : null; + switch (Options::getOption('pw_security_policy')) { // this could be better structured, switch doesn't feel right case 'off': $password = ['required', 'string', 'confirmed']; @@ -99,7 +104,15 @@ class RegisterController extends Controller 'dob.required' => __('Please enter your date of birth.'), 'uuid.required' => __('Please enter a valid (and Premium) Minecraft username! We do not support cracked users.'), 'acceptTerms.required' => __('Please accept the Community Guidelines, Terms of Service and Privacy Policy to continue.'), - ]); + + ])->after(function (\Illuminate\Validation\Validator $validator) use ($signupEnabled, $signupOverride, $signupOverrideEmail) { + + $email = $validator->getData()['email']; + + $validator->errors()->addIf(!$signupEnabled && !$signupOverride, 'signup', __('We\'re sorry, but new sign ups are currently closed and invite-only.')); + $validator->errors()->addIf($signupOverride && $email !== $signupOverrideEmail, 'email', 'You must sign up with the email address you were invited with.'); + + }); } /** @@ -124,6 +137,13 @@ class RegisterController extends Controller $user->assignRole('user'); + if (Session::get('ALLOW_REGISTRATION_OVERRIDE')) { + Session::forget([ + 'ALLOW_REGISTRATION_OVERRIDE', + 'REGISTRATION_OVERRIDE_EMAIL' + ]); + } + return $user; } } diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index b3c81c1..5dd1b34 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -14,9 +14,17 @@ - @if(\App\Facades\Options::getOption('enable_registrations') == true) + @if(\App\Facades\Options::getOption('enable_registrations') == true || session()->has('ALLOW_REGISTRATION_OVERRIDE'))

{{__('Sign up for an account')}}

+ @if(session()->has('ALLOW_REGISTRATION_OVERRIDE') && session('ALLOW_REGISTRATION_OVERRIDE') === true) +
+ {{ __('Invite only registration') }} +

{{ __('You are signing up with an invitation. Please use the original email address you were invited with to complete your registration. Any other email address will not work.') }}

+

{{ __('If you close the browser or otherwise clear your cookies, this page will NOT be available again if registrations are still closed.') }}

+
+ @endif + @if(\App\Facades\Options::getOption('pw_security_policy') !== 'off')