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. 4
      resources/views/auth/login.blade.php
  5. 74
      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_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_DEBUG=false
APP_URL=https://datatable.directory/
LOG_CHANNEL=stack
LOG_CHANNEL=custom
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_DATABASE=dtbl
DB_USERNAME=dtbl
DB_PASSWORD=secret
BROADCAST_DRIVER=log
@ -37,3 +36,20 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
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\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
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.
@ -41,6 +44,15 @@ class RegisterController extends Controller
$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.
*

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

@ -23,7 +23,9 @@
<ul class="col-md-8 offset-md-4 sr-list">
<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 px-1" href="{{ route('register') }}">{{ __('Register') }}</a>
@if(config('app.allow_regs'))
<li><a class="btn btn-link px-1" href="{{ route('register') }}">{{ __('Register') }}</a>
@endif
</ul>
</div>
</form>

@ -1,48 +1,56 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h1>{{ __('Register') }}</h1>
</div>
<div class="col-md-8">
<div class="card">
<div class="card-header">
<h1>{{ __('Register') }}</h1>
</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}">
@csrf
@if(config('app.allow_regs'))
@php(Widget::setLayout(4, 6))
<div class="card-body">
<form method="POST" action="{{ route('register') }}" aria-label="{{ __('Register') }}">
@csrf
{!! Widget::text('name', 'Username')->required()->prepend('@')
->help('This will be part of your vanity URL; only letters, digits and
some symbols are allowed. You can always change this later.') !!}
@php(Widget::setLayout(4, 6))
{!! Widget::email('email', 'E-Mail Address')->required()->autofocus()
->help('Used to login and for password resets') !!}
{!! Widget::text('name', 'Username')->required()->prepend('@')
->help('This will be part of your vanity URL; only letters, digits and
some symbols are allowed. You can always change this later.') !!}
{!! Widget::password('password', 'Password')->required() !!}
{!! Widget::password('password_confirmation', 'Confirm Password')->required() !!}
{!! Widget::email('email', 'E-Mail Address')->required()->autofocus()
->help('Used to login and for password resets') !!}
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
{!! Widget::password('password', 'Password')->required() !!}
{!! Widget::password('password_confirmation', 'Confirm Password')->required() !!}
<div class="card-footer bg-white text-muted">
You can also register by logging in with
<a href="{{route('oauth-google-authorize')}}">Google</a>,
<a href="{{route('oauth-github-authorize')}}">GitHub</a>,
or <a href="{{route('oauth-facebook-authorize')}}">Facebook</a>.
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
<div class="card-footer bg-white text-muted">
You can also register by logging in with
<a href="{{route('oauth-google-authorize')}}">Google</a>,
<a href="{{route('oauth-github-authorize')}}">GitHub</a>,
or <a href="{{route('oauth-facebook-authorize')}}">Facebook</a>.
</div>
@else
<div class="card-body">
<p>Registrations are currently closed.</p>
</div>
@endif
</div>
</div>
</div>
</div>
</div>
@endsection

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

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

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

Loading…
Cancel
Save