add toggle to disable regs

pull/26/head
Ondřej Hruška 6 years ago
parent 886c65b28e
commit 8047a0487f
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 34
      .env.example
  2. 14
      app/Http/Controllers/Auth/RegisterController.php
  3. 2
      config/app.php
  4. 2
      resources/views/auth/login.blade.php
  5. 12
      resources/views/auth/register.blade.php
  6. 14
      resources/views/layouts/main-nav.blade.php
  7. 4
      routes/login.php
  8. 4
      sideload/adamwathan/eloquent-oauth/src/Authenticator.php

@ -1,16 +1,15 @@
APP_NAME=Laravel APP_NAME=datatable.directory
APP_ENV=local APP_ENV=local
APP_KEY= APP_KEY=
APP_DEBUG=true APP_DEBUG=false
APP_URL=http://localhost APP_URL=https://datatable.directory/
LOG_CHANNEL=stack LOG_CHANNEL=custom
DB_CONNECTION=mysql DB_CONNECTION=pgsql
DB_HOST=127.0.0.1 DB_HOST=postgres
DB_PORT=3306 DB_DATABASE=dtbl
DB_DATABASE=homestead DB_USERNAME=dtbl
DB_USERNAME=homestead
DB_PASSWORD=secret DB_PASSWORD=secret
BROADCAST_DRIVER=log BROADCAST_DRIVER=log
@ -37,3 +36,20 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
PRETTY_JSON=true
OAUTH_GITHUB_ID=
OAUTH_GITHUB_SECRET=
OAUTH_GITHUB_REDIRECT=https://datatable.directory/auth/github/callback
OAUTH_GOOGLE_ID=
OAUTH_GOOGLE_SECRET=
OAUTH_GOOGLE_REDIRECT=https://datatable.directory/auth/google/callback
OAUTH_FACEBOOK_ID=
OAUTH_FACEBOOK_SECRET=
OAUTH_FACEBOOK_REDIRECT=https://datatable.directory/auth/facebook/callback
ALLOW_REGS=true

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Models\User; use App\Models\User;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Foundation\Auth\RegistersUsers;
@ -22,7 +23,9 @@ class RegisterController extends Controller
| |
*/ */
use RegistersUsers; use RegistersUsers {
RegistersUsers::register as register_orig;
}
/** /**
* Where to redirect users after registration. * Where to redirect users after registration.
@ -41,6 +44,15 @@ class RegisterController extends Controller
$this->middleware('guest'); $this->middleware('guest');
} }
public function register(Request $request)
{
if (!config('app.allow_regs')) {
abort(403, "Registrations are closed.");
}
return $this->register_orig($request);
}
/** /**
* Get a validator for an incoming registration request. * Get a validator for an incoming registration request.
* *

@ -229,4 +229,6 @@ return [
'_SERVER' => array_keys($_SERVER), '_SERVER' => array_keys($_SERVER),
'_ENV' => array_keys($_ENV), '_ENV' => array_keys($_ENV),
], ],
'allow_regs' => env('ALLOW_REGS', true),
]; ];

@ -23,7 +23,9 @@
<ul class="col-md-8 offset-md-4 sr-list"> <ul class="col-md-8 offset-md-4 sr-list">
<li><button type="submit" class="btn btn-primary">{{ __('Login') }}</button> <li><button type="submit" class="btn btn-primary">{{ __('Login') }}</button>
<li><a class="btn btn-link pr-1 pl-2" href="{{ route('password.request') }}">{{ __('Forgot Your Password?') }}</a> <li><a class="btn btn-link pr-1 pl-2" href="{{ route('password.request') }}">{{ __('Forgot Your Password?') }}</a>
@if(config('app.allow_regs'))
<li><a class="btn btn-link px-1" href="{{ route('register') }}">{{ __('Register') }}</a> <li><a class="btn btn-link px-1" href="{{ route('register') }}">{{ __('Register') }}</a>
@endif
</ul> </ul>
</div> </div>
</form> </form>

@ -1,7 +1,7 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">
<div class="card"> <div class="card">
@ -9,6 +9,8 @@
<h1>{{ __('Register') }}</h1> <h1>{{ __('Register') }}</h1>
</div> </div>
@if(config('app.allow_regs'))
<div class="card-body"> <div class="card-body">
<form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}"> <form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}">
@csrf @csrf
@ -41,8 +43,14 @@
<a href="{{route('oauth-github-authorize')}}">GitHub</a>, <a href="{{route('oauth-github-authorize')}}">GitHub</a>,
or <a href="{{route('oauth-facebook-authorize')}}">Facebook</a>. or <a href="{{route('oauth-facebook-authorize')}}">Facebook</a>.
</div> </div>
@else
<div class="card-body">
<p>Registrations are currently closed.</p>
</div>
@endif
</div>
</div> </div>
</div> </div>
</div> </div>
</div>
@endsection @endsection

@ -7,13 +7,9 @@
--}}datatable.directory --}}datatable.directory
</a> </a>
<button class="navbar-toggler" <button class="navbar-toggler" type="button" data-toggle="collapse"
type="button" data-target="#mainNavContent" aria-controls="mainNavContent"
data-toggle="collapse" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
data-target="#mainNavContent"
aria-controls="mainNavContent"
aria-expanded="false"
aria-label="{{ __('Toggle navigation') }}">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
@ -28,12 +24,16 @@
{{ __('Login') }} {{ __('Login') }}
</a> </a>
@if(config('app.allow_regs'))
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ route('register') }}"> <a class="nav-link" href="{{ route('register') }}">
@icon(fa-user-plus pr-1) @icon(fa-user-plus pr-1)
{{ __('Register') }} {{ __('Register') }}
</a> </a>
@endif
@else @else
{{-- Logged in --}}
@include('layouts.nav-buttons', ['dropdown' => false]) @include('layouts.nav-buttons', ['dropdown' => false])
<li class="nav-item dropdown mobile-only"> <li class="nav-item dropdown mobile-only">

@ -32,6 +32,10 @@ function _loginVia($method) {
// update user name first time user logs in // update user name first time user logs in
if (!$user->exists) { if (!$user->exists) {
if (!config('app.allow_regs')) {
abort(403, "Registrations are closed.");
}
$basename = $details->nickname ?: ($details->full_name ?: $details->email); $basename = $details->nickname ?: ($details->full_name ?: $details->email);
$user->name = $basename; $user->name = $basename;
$cnt = 1; $cnt = 1;

@ -43,6 +43,10 @@ class Authenticator
return $this->users->findByEmail($details->email); return $this->users->findByEmail($details->email);
} }
if(!config('app.allow_regs', true)) {
abort(403, "Registrations are currently closed.");
}
return $this->users->create(); return $this->users->create();
} }

Loading…
Cancel
Save