Update middleware, add AccountInterstitial support

This commit is contained in:
Daniel Supernault 2020-12-09 21:59:16 -07:00
parent b8330b3d92
commit 19d6e7df65
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
3 changed files with 58 additions and 1 deletions

View file

@ -66,6 +66,7 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'twofactor' => \App\Http\Middleware\TwoFactorAuth::class, 'twofactor' => \App\Http\Middleware\TwoFactorAuth::class,
'validemail' => \App\Http\Middleware\EmailVerificationCheck::class, 'validemail' => \App\Http\Middleware\EmailVerificationCheck::class,
'interstitial' => \App\Http\Middleware\AccountInterstitial::class,
// 'restricted' => \App\Http\Middleware\RestrictedAccess::class, // 'restricted' => \App\Http\Middleware\RestrictedAccess::class,
]; ];
} }

View file

@ -0,0 +1,48 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
use App\User;
class AccountInterstitial
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$ar = [
'login',
'logout',
'password*',
'loginAs*',
'i/warning*',
'i/auth/checkpoint',
'i/auth/sudo',
'site/privacy',
'site/terms',
'site/kb/community-guidelines',
];
if(Auth::check() && !$request->is($ar)) {
if($request->user()->has_interstitial) {
if($request->wantsJson()) {
$res = ['_refresh'=>true,'error' => 403, 'message' => \App\AccountInterstitial::JSON_MESSAGE];
return response()->json($res, 403);
} else {
return redirect('/i/warning');
}
} else {
return $next($request);
}
} else {
return $next($request);
}
}
}

View file

@ -8,6 +8,9 @@ Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(functio
Route::get('reports/show/{id}', 'AdminController@showReport'); Route::get('reports/show/{id}', 'AdminController@showReport');
Route::post('reports/show/{id}', 'AdminController@updateReport'); Route::post('reports/show/{id}', 'AdminController@updateReport');
Route::post('reports/bulk', 'AdminController@bulkUpdateReport'); Route::post('reports/bulk', 'AdminController@bulkUpdateReport');
Route::get('reports/appeals', 'AdminController@appeals');
Route::get('reports/appeal/{id}', 'AdminController@showAppeal');
Route::post('reports/appeal/{id}', 'AdminController@updateAppeal');
Route::redirect('statuses', '/statuses/list'); Route::redirect('statuses', '/statuses/list');
Route::get('statuses/list', 'AdminController@statuses')->name('admin.statuses'); Route::get('statuses/list', 'AdminController@statuses')->name('admin.statuses');
Route::get('statuses/show/{id}', 'AdminController@showStatus'); Route::get('statuses/show/{id}', 'AdminController@showStatus');
@ -73,7 +76,7 @@ Route::domain(config('pixelfed.domain.admin'))->prefix('i/admin')->group(functio
Route::post('newsroom/create', 'AdminController@newsroomStore'); Route::post('newsroom/create', 'AdminController@newsroomStore');
}); });
Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization'])->group(function () { Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofactor', 'localization','interstitial'])->group(function () {
Route::get('/', 'SiteController@home')->name('timeline.personal'); Route::get('/', 'SiteController@home')->name('timeline.personal');
Route::post('/', 'StatusController@store'); Route::post('/', 'StatusController@store');
@ -125,6 +128,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('discover/tag', 'DiscoverController@getHashtags'); Route::get('discover/tag', 'DiscoverController@getHashtags');
Route::post('status/compose', 'InternalApiController@composePost')->middleware('throttle:maxPostsPerHour,60')->middleware('throttle:maxPostsPerDay,1440'); Route::post('status/compose', 'InternalApiController@composePost')->middleware('throttle:maxPostsPerHour,60')->middleware('throttle:maxPostsPerDay,1440');
}); });
Route::group(['prefix' => 'pixelfed'], function() { Route::group(['prefix' => 'pixelfed'], function() {
Route::group(['prefix' => 'v1'], function() { Route::group(['prefix' => 'v1'], function() {
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials'); Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials');
@ -169,6 +173,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('discover/posts/places', 'DiscoverController@trendingPlaces'); Route::get('discover/posts/places', 'DiscoverController@trendingPlaces');
}); });
}); });
Route::group(['prefix' => 'local'], function () { Route::group(['prefix' => 'local'], function () {
// Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials'); // Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials');
// Route::get('accounts/relationships', 'PublicApiController@relationships'); // Route::get('accounts/relationships', 'PublicApiController@relationships');
@ -295,6 +300,9 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
Route::get('redirect', 'SiteController@redirectUrl'); Route::get('redirect', 'SiteController@redirectUrl');
Route::post('admin/media/block/add', 'MediaBlocklistController@add'); Route::post('admin/media/block/add', 'MediaBlocklistController@add');
Route::post('admin/media/block/delete', 'MediaBlocklistController@delete'); Route::post('admin/media/block/delete', 'MediaBlocklistController@delete');
Route::get('warning', 'AccountInterstitialController@get');
Route::post('warning', 'AccountInterstitialController@read');
}); });
Route::group(['prefix' => 'account'], function () { Route::group(['prefix' => 'account'], function () {