mirror of
https://github.com/prurigro/hypothetical.git
synced 2024-12-26 11:14:34 -05:00
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:
parent
70a8b83b85
commit
9fa8479ed8
3 changed files with 17 additions and 3 deletions
|
@ -84,4 +84,15 @@ class Dashboard
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\User;
|
||||
use App\Dashboard;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
@ -61,13 +62,15 @@ class RegisterController extends Controller {
|
|||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
if (env('REGISTRATION', false)) {
|
||||
if (Dashboard::canRegister()) {
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
'api_token' => str_random(60)
|
||||
]);
|
||||
} else {
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +81,7 @@ class RegisterController extends Controller {
|
|||
*/
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
if (env('REGISTRATION', false)) {
|
||||
if (Dashboard::canRegister()) {
|
||||
return view('auth.register');
|
||||
} else {
|
||||
header('Location: /login');
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
@if (Auth::guest())
|
||||
<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>
|
||||
@endif
|
||||
@else
|
||||
|
|
Loading…
Reference in a new issue