Improve the functionality surrounding the REGISTRATION variable in the .env file so it can continue to enable registration globally by setting its value to "true", but now also enable registration for a single IP address by setting its value to that address

This commit is contained in:
Kevin MacMartin 2018-04-25 21:22:39 -04:00
parent 70a8b83b85
commit 9fa8479ed8
3 changed files with 17 additions and 3 deletions

View file

@ -84,4 +84,15 @@ class Dashboard
return null; return null;
} }
} }
/**
* Checks the registration status against the REGISTRATION variable in .env
*
* @return boolean
*/
public static function canRegister()
{
$registration_status = env('REGISTRATION', false);
return $registration_status === true || $registration_status === \Request::ip();
}
} }

View file

@ -1,6 +1,7 @@
<?php namespace App\Http\Controllers\Auth; <?php namespace App\Http\Controllers\Auth;
use App\User; use App\User;
use App\Dashboard;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
@ -61,13 +62,15 @@ class RegisterController extends Controller {
*/ */
protected function create(array $data) protected function create(array $data)
{ {
if (env('REGISTRATION', false)) { if (Dashboard::canRegister()) {
return User::create([ return User::create([
'name' => $data['name'], 'name' => $data['name'],
'email' => $data['email'], 'email' => $data['email'],
'password' => Hash::make($data['password']), 'password' => Hash::make($data['password']),
'api_token' => str_random(60) 'api_token' => str_random(60)
]); ]);
} else {
abort(404);
} }
} }
@ -78,7 +81,7 @@ class RegisterController extends Controller {
*/ */
public function showRegistrationForm() public function showRegistrationForm()
{ {
if (env('REGISTRATION', false)) { if (Dashboard::canRegister()) {
return view('auth.register'); return view('auth.register');
} else { } else {
header('Location: /login'); header('Location: /login');

View file

@ -16,7 +16,7 @@
@if (Auth::guest()) @if (Auth::guest())
<li class="nav-item"><a class="nav-link {{ $current_page == 'login' ? 'active' : '' }}" href="/login">Login</a></li> <li class="nav-item"><a class="nav-link {{ $current_page == 'login' ? 'active' : '' }}" href="/login">Login</a></li>
@if(env('REGISTRATION', false)) @if(App\Dashboard::canRegister())
<li class="nav-item"><a class="nav-link {{ $current_page == 'register' ? 'active' : '' }}" href="/register">Register</a></li> <li class="nav-item"><a class="nav-link {{ $current_page == 'register' ? 'active' : '' }}" href="/register">Register</a></li>
@endif @endif
@else @else