mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-27 05:50:51 -05:00
(Add) Email Whitelist / Blacklist System
- Blacklist means that you won’t be able to sign-up with and or send invites to a email email on blacklist. - Whitelist means that you will only be able to sign-up with and or send invites to a whitelisted email. - Set “enabled” to null to not use either
This commit is contained in:
@@ -50,20 +50,20 @@ class RegisterController extends Controller
|
||||
*/
|
||||
public function registrationForm($code = null)
|
||||
{
|
||||
// Make sure open reg is off and invite code is present
|
||||
if ($code === 'null' && config('other.invite-only') == 1) {
|
||||
return view('auth.login')
|
||||
->with(Toastr::error('Open Reg Closed! You Must Be Invited To Register! You Have Been Redirected To Login Page!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
return view('auth.register', ['code' => $code]);
|
||||
}
|
||||
|
||||
public function register(Request $request, $code = null)
|
||||
{
|
||||
// Make sure open reg is off and invite code is present
|
||||
if (config('other.invite-only') == true && $code == null) {
|
||||
return view('auth.login')
|
||||
->with(Toastr::error('Open Reg Closed! You Must Be Invited To Register! You Have Been Redirected To Login Page!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
// Make sure open reg is off and invite code exist and has not been used already
|
||||
$key = Invite::where('code', '=', $code)->first();
|
||||
if (config('other.invite-only') == true && (!$key || $key->accepted_by !== null)) {
|
||||
if (config('other.invite-only') == 1 && (!$key || $key->accepted_by !== null)) {
|
||||
return view('auth.register', ['code' => $code])
|
||||
->with(Toastr::error('Invalid or Expired Invite Key!', 'Whoops!', ['options']));
|
||||
}
|
||||
@@ -80,12 +80,28 @@ class RegisterController extends Controller
|
||||
$user->style = config('other.default_style', 0);
|
||||
$user->group_id = $group->id;
|
||||
|
||||
$v = validator($request->all(), [
|
||||
'username' => 'required|alpha_dash|min:3|max:20|unique:users',
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|min:6',
|
||||
'g-recaptcha-response' => new Captcha()
|
||||
]);
|
||||
if (config('email-white-blacklist.enabled') === 'allow'){
|
||||
$v = validator($request->all(), [
|
||||
'username' => 'required|alpha_dash|min:3|max:20|unique:users',
|
||||
'email' => 'required|email|max:255|unique:users|email_list:allow', // Whitelist
|
||||
'password' => 'required|min:8',
|
||||
'g-recaptcha-response' => new Captcha()
|
||||
]);
|
||||
} elseif (config('email-white-blacklist.enabled') === 'block') {
|
||||
$v = validator($request->all(), [
|
||||
'username' => 'required|alpha_dash|min:3|max:20|unique:users',
|
||||
'email' => 'required|email|max:255|unique:users|email_list:block', // Blacklist
|
||||
'password' => 'required|min:8',
|
||||
'g-recaptcha-response' => new Captcha()
|
||||
]);
|
||||
} else {
|
||||
$v = validator($request->all(), [
|
||||
'username' => 'required|alpha_dash|min:3|max:20|unique:users', //Default
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|min:8',
|
||||
'g-recaptcha-response' => new Captcha()
|
||||
]);
|
||||
}
|
||||
|
||||
if ($v->fails()) {
|
||||
return redirect()->route('register', ['code' => $code])
|
||||
|
||||
@@ -61,6 +61,11 @@ class InviteController extends Controller
|
||||
->with(Toastr::error('Invites are currently disabled for your group.', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->invites <= 0) {
|
||||
return redirect()->route('invite')
|
||||
->with(Toastr::error('You do not have enough invites!', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
$exist = Invite::where('email', $request->input('email'))->first();
|
||||
$member = User::where('email', $request->input('email'))->first();
|
||||
|
||||
@@ -69,18 +74,38 @@ class InviteController extends Controller
|
||||
->with(Toastr::error('The email address your trying to send a invite to has already been sent one or is a used already.', 'Whoops!', ['options']));
|
||||
}
|
||||
|
||||
if ($user->invites > 0) {
|
||||
$code = Uuid::uuid4()->toString();
|
||||
$code = Uuid::uuid4()->toString();
|
||||
$invite = new Invite();
|
||||
$invite->user_id = $user->id;
|
||||
$invite->email = $request->input('email');
|
||||
$invite->code = $code;
|
||||
$invite->expires_on = $current->copy()->addDays(config('other.invite_expire'));
|
||||
$invite->custom = $request->input('message');
|
||||
|
||||
$invite = new Invite();
|
||||
$invite->user_id = $user->id;
|
||||
$invite->email = $request->input('email');
|
||||
$invite->code = $code;
|
||||
$invite->expires_on = $current->copy()->addDays(config('other.invite_expire'));
|
||||
$invite->custom = $request->input('message');
|
||||
$invite->save();
|
||||
if (config('email-white-blacklist.enabled') === 'allow'){
|
||||
$v = validator($invite->toArray(), [
|
||||
"email" => "required|email|email_list:allow", // Whitelist
|
||||
"custom" => "required"
|
||||
]);
|
||||
} elseif (config('email-white-blacklist.enabled') === 'block') {
|
||||
$v = validator($invite->toArray(), [
|
||||
"email" => "required|email|email_list:block", // Blacklist
|
||||
"custom" => "required"
|
||||
]);
|
||||
} else {
|
||||
$v = validator($invite->toArray(), [
|
||||
"email" => "required|email", // Default
|
||||
"custom" => "required"
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
if ($v->fails()) {
|
||||
return redirect()->route('invite')
|
||||
->with(Toastr::error($v->errors()->toJson(), 'Whoops!', ['options']));
|
||||
} else {
|
||||
Mail::to($request->input('email'))->send(new InviteUser($invite));
|
||||
$invite->save();
|
||||
|
||||
$user->invites -= 1;
|
||||
$user->save();
|
||||
@@ -88,9 +113,8 @@ class InviteController extends Controller
|
||||
// Activity Log
|
||||
\LogActivity::addToLog("Member {$user->username} has sent a invite to {$invite->email} .");
|
||||
|
||||
return redirect()->route('invite')->with(Toastr::success('Invite was sent successfully!', 'Yay!', ['options']));
|
||||
} else {
|
||||
return redirect()->route('invite')->with(Toastr::error('You do not have enough invites!', 'Whoops!', ['options']));
|
||||
return redirect()->route('invite')
|
||||
->with(Toastr::success('Invite was sent successfully!', 'Yay!', ['options']));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,4 +77,17 @@ class PageController extends Controller
|
||||
{
|
||||
return view('page.aboutus');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Email Whitelist / Blacklist Page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function emailList()
|
||||
{
|
||||
$whitelist = config('email-white-blacklist.allow', []);
|
||||
$blacklist = config('email-white-blacklist.block', []);
|
||||
|
||||
return view('page.emaillist', ['whitelist' => $whitelist, 'blacklist' => $blacklist]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ namespace App\Providers;
|
||||
use App\Repositories\WishInterface;
|
||||
use App\Repositories\WishRepository;
|
||||
use App\Services\Clients\OmdbClient;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
@@ -27,7 +27,8 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
// Custom validation for the email whitelist/blacklist
|
||||
Validator::extend('email_list', 'App\Validators\EmailValidator@validateEmailList');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
* @author HDVinnie
|
||||
*/
|
||||
|
||||
namespace App\Validators;
|
||||
|
||||
class EmailValidator
|
||||
{
|
||||
public function validateEmailList($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
$domain = substr(strrchr($value, "@"), 1);
|
||||
switch ($parameters[0]) {
|
||||
case 'block':
|
||||
$domain_list = config('email-white-blacklist.block');
|
||||
return !in_array($domain, $domain_list);
|
||||
break;
|
||||
case 'allow':
|
||||
$domain_list = config('email-white-blacklist.allow');
|
||||
return in_array($domain, $domain_list);
|
||||
break;
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* UNIT3D is open-sourced software licensed under the GNU General Public License v3.0
|
||||
* The details is bundled with this project in the file LICENSE.txt.
|
||||
*
|
||||
* @project UNIT3D
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
||||
* @author HDVinnie
|
||||
*/
|
||||
|
||||
return [
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| whitelist = allow / blacklist = block / disabled = null
|
||||
|
|
||||
*/
|
||||
|
||||
'enabled' => 'null',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Blacklist
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Domains you want to block e.g mailinator.com
|
||||
|
|
||||
*/
|
||||
'block' => [
|
||||
//
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Whitelist
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Domains you want to allow e.g gmail.com
|
||||
|
|
||||
*/
|
||||
'allow' => [
|
||||
//
|
||||
],
|
||||
];
|
||||
@@ -17,7 +17,7 @@ return [
|
||||
'anonymous' => 'Anonymous',
|
||||
'author' => 'Author',
|
||||
'balance' => 'Balance',
|
||||
'blacklist' => 'Blacklist',
|
||||
'blacklist' => 'Client Blacklist',
|
||||
'buffer' => 'Buffer',
|
||||
'bug' => 'Report A Bug',
|
||||
'but' => 'But',
|
||||
@@ -38,6 +38,9 @@ return [
|
||||
'edit' => 'Edit',
|
||||
'edit-your-comment' => 'Edit your comment',
|
||||
'email' => 'E-mail',
|
||||
'email-blacklist' => 'Email Blacklist',
|
||||
'email-whitelist' => 'Email Whitelist',
|
||||
'email-list-notactive' => 'Email Whitelist / Blacklist System Is Not Activated',
|
||||
'enter' => 'Enter',
|
||||
'error' => 'Error',
|
||||
'everyday' => 'Everyday',
|
||||
@@ -87,7 +90,7 @@ return [
|
||||
'notifications' => 'Notifications',
|
||||
'older-than' => 'Older than',
|
||||
'oldest' => 'Oldest',
|
||||
'openreg_activated' => 'Global Open registration activated',
|
||||
'openreg_activated' => 'Open registration activated',
|
||||
'order-by' => 'Order by',
|
||||
'other' => 'Other',
|
||||
'pages' => 'Pages',
|
||||
|
||||
@@ -23,6 +23,10 @@ return [
|
||||
'blacklist-clients' => 'Clients',
|
||||
'blacklist-desc' => 'The Following Browsers and Bittorrent Clients Are Blacklisted/Forbidden From Annoucing To :title',
|
||||
'blacklist-webbrowser' => 'Web Browser',
|
||||
'blacklist-emaildomain' => 'Blocked Domain',
|
||||
'email-blacklist-desc' => 'The Following Email Domains Are Blocked From Being Used. You Cannot Register Or Send A Invite To The Following.',
|
||||
'email-whitelist-desc' => 'The Following Email Domains Are The Only Email Domains Allowed To Be Used. You May Only Register Or Send A Invite Using The Following.',
|
||||
'staff-group' => 'Group',
|
||||
'staff-title' => 'Title'
|
||||
'staff-title' => 'Title',
|
||||
'whitelist-emaildomain' => 'Trusted Domain'
|
||||
];
|
||||
|
||||
@@ -81,36 +81,38 @@ return [
|
||||
'timezone' => 'The :attribute must be a valid zone.',
|
||||
'unique' => 'The :attribute has already been taken.',
|
||||
'uploaded' => 'The :attribute failed to upload.',
|
||||
'url' => 'The :attribute format is invalid.',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify custom validation messages for attributes using the
|
||||
| convention "attribute.rule" to name the lines. This makes it quick to
|
||||
| specify a specific custom language line for a given attribute rule.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => 'The :attribute format is invalid.',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Language Lines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify custom validation messages for attributes using the
|
||||
| convention "attribute.rule" to name the lines. This makes it quick to
|
||||
| specify a specific custom language line for a given attribute rule.
|
||||
|
|
||||
*/
|
||||
'email_list' => 'Sorry, this email domain is not allowed to be used on this site. Please see sites email whitelist.',
|
||||
|
||||
'custom' => [
|
||||
'attribute-name' => [
|
||||
'rule-name' => 'custom-message'
|
||||
]
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Attributes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines are used to swap attribute place-holders
|
||||
| with something more reader friendly such as E-Mail Address instead
|
||||
| of "email". This simply helps us make messages a little cleaner.
|
||||
|
|
||||
*/
|
||||
|
||||
'rule-name' => 'custom-message',
|
||||
],
|
||||
],
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Custom Validation Attributes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following language lines are used to swap attribute place-holders
|
||||
| with something more reader friendly such as E-Mail Address instead
|
||||
| of "email". This simply helps us make messages a little cleaner.
|
||||
|
|
||||
*/
|
||||
|
||||
'attributes' => []
|
||||
|
||||
];
|
||||
];
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
@extends('layout.default')
|
||||
|
||||
@section('breadcrumb')
|
||||
<li>
|
||||
<a href="{{ route('emaillist') }}" itemprop="url" class="l-breadcrumb-item-link">
|
||||
<span itemprop="title" class="l-breadcrumb-item-link-title">
|
||||
@if (config('email-white-blacklist.enabled') == 'allow')
|
||||
{{ config('other.title') }} {{ trans('common.email-whitelist') }}
|
||||
@endif
|
||||
@if (config('email-white-blacklist.enabled') == 'block')
|
||||
{{ config('other.title') }} {{ trans('common.email-blacklist') }}
|
||||
@endif
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container box">
|
||||
<div class="col-md-12 page">
|
||||
|
||||
@if (config('email-white-blacklist.enabled') == null)
|
||||
<div class="alert alert-info" id="alert1">
|
||||
<div class="text-center">
|
||||
<span>
|
||||
{{ config('other.title') }} {{ trans('common.email-list-notactive') }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
|
||||
@if (config('email-white-blacklist.enabled') == 'allow')
|
||||
<div class="header gradient green">
|
||||
<div class="inner_content">
|
||||
<div class="page-title"><h1>{{ config('other.title') }} {{ trans('common.email-whitelist') }}</h1></div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if (config('email-white-blacklist.enabled') == 'block')
|
||||
<div class="header gradient red">
|
||||
<div class="inner_content">
|
||||
<div class="page-title"><h1>{{ config('other.title') }} {{ trans('common.email-blacklist') }}</h1></div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="alert alert-info" id="alert1">
|
||||
<div class="text-center">
|
||||
@if (config('email-white-blacklist.enabled') == 'allow')
|
||||
<span>
|
||||
{{ trans('page.email-whitelist-desc', ['title' => config('other.title')]) }}
|
||||
</span>
|
||||
@endif
|
||||
@if (config('email-white-blacklist.enabled') == 'block')
|
||||
<span>
|
||||
{{ trans('page.email-blacklist-desc', ['title' => config('other.title')]) }}
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (config('email-white-blacklist.enabled') == 'allow')
|
||||
<div class="row black-list">
|
||||
@foreach($whitelist as $w)
|
||||
<div class="col-xs-6 col-sm-4 col-md-3">
|
||||
<div class="text-center black-item">
|
||||
<span class="text-bold">{{ $w }}</span>
|
||||
<h4>{{ trans('page.whitelist-emaildomain') }}</h4>
|
||||
<i class="fa fa-check text-green black-icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if (config('email-white-blacklist.enabled') == 'block')
|
||||
<div class="row black-list">
|
||||
@foreach($blacklist as $b)
|
||||
<div class="col-xs-6 col-sm-4 col-md-3">
|
||||
<div class="text-center black-item">
|
||||
<span class="text-bold">{{ $b }}</span>
|
||||
<h4>{{ trans('page.blacklist-emaildomain') }}</h4>
|
||||
<i class="fa fa-ban text-red black-icon"></i>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
@@ -43,6 +43,12 @@
|
||||
<li><a href="{{ route('blacklist') }}">{{ trans('common.blacklist') }}</a></li>
|
||||
<li><a href="{{ route('home') }}/p/tracker-codes.6">{{ trans('common.tracker-codes') }}</a></li>
|
||||
<li><a href="{{ route('home') }}/p/upload-guide.5">{{ trans('common.upload-guide') }}</a></li>
|
||||
@if (config('email-white-blacklist.enabled') == 'allow')
|
||||
<li><a href="{{ route('emaillist') }}">{{ trans('common.email-whitelist') }}</a></li>
|
||||
@endif
|
||||
@if (config('email-white-blacklist.enabled') == 'block')
|
||||
<li><a href="{{ route('emaillist') }}">{{ trans('common.email-blacklist') }}</a></li>
|
||||
@endif
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
+5
-2
@@ -116,15 +116,18 @@ Route::group(['middleware' => 'language'], function () {
|
||||
// Staff List
|
||||
Route::get('/staff', 'PageController@staff')->name('staff');
|
||||
|
||||
// Internal List
|
||||
// Internals List
|
||||
Route::get('/internal', 'PageController@internal')->name('internal');
|
||||
|
||||
// Black List
|
||||
// Client Blacklist
|
||||
Route::get('/blacklist', 'PageController@blacklist')->name('blacklist');
|
||||
|
||||
// About Us
|
||||
Route::get('/aboutus', 'PageController@about')->name('about');
|
||||
|
||||
// Email Whitelist / Blacklist
|
||||
Route::get('/emaillist', 'PageController@emailList')->name('emaillist');
|
||||
|
||||
// Comments
|
||||
Route::post('/comment/article/{slug}.{id}', 'CommentController@article')->name('comment_article');
|
||||
Route::post('/comment/torrent/{slug}.{id}', 'CommentController@torrent')->name('comment_torrent');
|
||||
|
||||
Reference in New Issue
Block a user