mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
No longer able to manage blocked domains.
This commit is contained in:
parent
9ef24c0a43
commit
04b284f030
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* DomainController.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Class DomainController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers\Admin
|
||||
*/
|
||||
class DomainController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function domains()
|
||||
{
|
||||
|
||||
$title = strval(trans('firefly.administration'));
|
||||
$mainTitleIcon = 'fa-hand-spock-o';
|
||||
$subTitle = strval(trans('firefly.blocked_domains'));
|
||||
$subTitleIcon = 'fa-exclamation-circle';
|
||||
$domains = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
// known domains
|
||||
$knownDomains = $this->getKnownDomains();
|
||||
|
||||
return view('admin.domains.index', compact('title', 'mainTitleIcon', 'knownDomains', 'subTitle', 'subTitleIcon', 'domains'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function manual(Request $request)
|
||||
{
|
||||
if (strlen($request->get('domain')) === 0) {
|
||||
Session::flash('error', trans('firefly.no_domain_filled_in'));
|
||||
|
||||
return redirect(route('admin.users.domains'));
|
||||
}
|
||||
|
||||
$domain = strtolower($request->get('domain'));
|
||||
$blocked = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
if (in_array($domain, $blocked)) {
|
||||
Session::flash('error', trans('firefly.domain_already_blocked', ['domain' => $domain]));
|
||||
|
||||
return redirect(route('admin.users.domains'));
|
||||
}
|
||||
$blocked[] = $domain;
|
||||
FireflyConfig::set('blocked-domains', $blocked);
|
||||
|
||||
Session::flash('success', trans('firefly.domain_is_now_blocked', ['domain' => $domain]));
|
||||
|
||||
return redirect(route('admin.users.domains'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $domain
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function toggleDomain(string $domain)
|
||||
{
|
||||
$domain = strtolower($domain);
|
||||
$blocked = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
if (in_array($domain, $blocked)) {
|
||||
$key = array_search($domain, $blocked);
|
||||
unset($blocked[$key]);
|
||||
sort($blocked);
|
||||
|
||||
FireflyConfig::set('blocked-domains', $blocked);
|
||||
Session::flash('message', trans('firefly.domain_now_unblocked', ['domain' => $domain]));
|
||||
|
||||
|
||||
return redirect(route('admin.users.domains'));
|
||||
|
||||
}
|
||||
|
||||
$blocked[] = $domain;
|
||||
|
||||
FireflyConfig::set('blocked-domains', $blocked);
|
||||
Session::flash('message', trans('firefly.domain_now_blocked', ['domain' => $domain]));
|
||||
|
||||
return redirect(route('admin.users.domains'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getKnownDomains(): array
|
||||
{
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$users = $repository->all();
|
||||
$set = [];
|
||||
$filtered = [];
|
||||
/** @var User $user */
|
||||
foreach ($users as $user) {
|
||||
$email = $user->email;
|
||||
$parts = explode('@', $email);
|
||||
$set[] = strtolower($parts[1]);
|
||||
}
|
||||
$set = array_unique($set);
|
||||
// filter for already banned domains:
|
||||
$blocked = FireflyConfig::get('blocked-domains', [])->data;
|
||||
|
||||
foreach ($set as $domain) {
|
||||
// in the block array? ignore it.
|
||||
if (!in_array($domain, $blocked)) {
|
||||
$filtered[] = $domain;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
@ -72,9 +72,7 @@ class RegisterController extends Controller
|
||||
$this->throwValidationException($request, $validator);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
$user = $this->create($request->all());
|
||||
$user = $this->create($request->all());
|
||||
|
||||
// trigger user registration event:
|
||||
event(new RegisteredUser($user, $request->ip()));
|
||||
|
@ -832,18 +832,6 @@ return [
|
||||
'user_administration' => 'User administration',
|
||||
'list_all_users' => 'All users',
|
||||
'all_users' => 'All users',
|
||||
'all_blocked_domains' => 'All blocked domains',
|
||||
'blocked_domains' => 'Blocked domains',
|
||||
'no_domains_banned' => 'No domains blocked',
|
||||
'all_user_domains' => 'All user email address domains',
|
||||
'all_domains_is_filtered' => 'This list does not include already blocked domains.',
|
||||
'domain_now_blocked' => 'Domain :domain is now blocked',
|
||||
'domain_now_unblocked' => 'Domain :domain is now unblocked',
|
||||
'manual_block_domain' => 'Block a domain by hand',
|
||||
'block_domain' => 'Block domain',
|
||||
'no_domain_filled_in' => 'No domain filled in',
|
||||
'domain_already_blocked' => 'Domain :domain is already blocked',
|
||||
'domain_is_now_blocked' => 'Domain :domain is now blocked',
|
||||
'instance_configuration' => 'Configuration',
|
||||
'firefly_instance_configuration' => 'Configuration options for Firefly III',
|
||||
'setting_single_user_mode' => 'Single user mode',
|
||||
|
@ -1,122 +0,0 @@
|
||||
{% extends "./layout/default" %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
{{ Breadcrumbs.renderIfExists }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'all_blocked_domains'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body table-responsive no-padding">
|
||||
{% if domains|length > 0 %}
|
||||
<table class="table table-condensed table-hover sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-defaultsort="disabled" style="width:20%;"> </th>
|
||||
<th data-defaultsign="az">{{ trans('list.domain') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for domain in domains %}
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{{ route('admin.users.domains.block-toggle', [domain]) }}" class="btn btn-sm btn-success"><i
|
||||
class="fa fa-fw fa-times"></i> unblock</a>
|
||||
</td>
|
||||
<td data-value="{{ domain }}">
|
||||
<a href="http://{{ domain }}/">{{ domain }}</a>
|
||||
(<a href="http://whois.domaintools.com/{{ domain }}">whois</a>)
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p>
|
||||
<em>{{ 'no_domains_banned'|_ }}</em>
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- domains found in users (not in top list) -->
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'all_user_domains'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body table-responsive">
|
||||
{% if knownDomains|length > 0 %}
|
||||
<p>
|
||||
{{ 'all_domains_is_filtered'|_ }}
|
||||
|
||||
</p>
|
||||
<table class="table table-condensed table-hover sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-defaultsort="disabled" style="width:20%;"> </th>
|
||||
<th data-defaultsign="az">{{ trans('list.domain') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for domain in knownDomains %}
|
||||
<tr>
|
||||
<td><a href="{{ route('admin.users.domains.block-toggle', [domain]) }}" class="btn btn-sm btn-danger"><i
|
||||
class="fa fa-fw fa-check"></i> block</a></td>
|
||||
<td>{{ domain }}</td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="well">
|
||||
<em>{{ 'no_domains_banned'|_ }}</em>
|
||||
</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- block domain by hand -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'manual_block_domain'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
|
||||
<form action="{{ route('admin.users.domains.manual') }}" method="post" id="store" class="form-horizontal">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
|
||||
<input type="hidden" name="what" value="{{ what }}"/>
|
||||
|
||||
{{ ExpandedForm.text('domain') }}
|
||||
|
||||
<input type="submit" name="submit" class="btn btn-success" value="{{ ('block_domain')|_ }}"/>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block styles %}
|
||||
<link rel="stylesheet" href="css/bootstrap-sortable.css" type="text/css" media="all"/>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script type="text/javascript" src="js/lib/bootstrap-sortable.js"></script>
|
||||
{% endblock %}
|
@ -28,8 +28,6 @@
|
||||
<div class="box-body">
|
||||
<ul>
|
||||
<li><a href="{{ route('admin.users') }}">{{ 'list_all_users'|_ }}</a></li>
|
||||
<li><a href="{{ route('admin.users.domains') }}">{{ 'blocked_domains'|_ }}</a></li>
|
||||
<!-- <li><a href="#">{{ 'user_related_settings'|_ }}</a></li> -->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -684,11 +684,6 @@ Route::group(
|
||||
Route::get('users/show/{user}', ['uses' => 'UserController@show', 'as' => 'users.show']);
|
||||
Route::post('users/update/{user}', ['uses' => 'UserController@update', 'as' => 'users.update']);
|
||||
|
||||
// user domain manager
|
||||
Route::get('domains', ['uses' => 'DomainController@domains', 'as' => 'users.domains']);
|
||||
Route::get('domains/toggle/{domain}', ['uses' => 'DomainController@toggleDomain', 'as' => 'users.domains.block-toggle']);
|
||||
Route::post('domains/manual', ['uses' => 'DomainController@manual', 'as' => 'users.domains.manual']);
|
||||
|
||||
// FF configuration:
|
||||
Route::get('configuration', ['uses' => 'ConfigurationController@index', 'as' => 'configuration.index']);
|
||||
Route::post('configuration', ['uses' => 'ConfigurationController@postIndex', 'as' => 'configuration.index.post']);
|
||||
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* DomainControllerTest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Admin;
|
||||
|
||||
use TestCase;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2016-12-07 at 18:50:31.
|
||||
*/
|
||||
class DomainControllerTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\DomainController::domains
|
||||
*/
|
||||
public function testDomains()
|
||||
{
|
||||
|
||||
$this->be($this->user());
|
||||
$this->call('GET', route('admin.users.domains'));
|
||||
$this->assertResponseStatus(200);
|
||||
|
||||
// has bread crumb
|
||||
$this->see('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\DomainController::manual
|
||||
*/
|
||||
public function testManual()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$this->call('POST', route('admin.users.domains.manual'), ['domain' => 'example2.com']);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\DomainController::toggleDomain
|
||||
*/
|
||||
public function testToggleDomain()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$this->call('GET', route('admin.users.domains.block-toggle', ['example.com']));
|
||||
$this->assertSessionHas('message');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user