2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
2015-04-22 21:21:04 +02:00
|
|
|
|
|
|
|
use Closure;
|
2016-07-03 18:11:58 +02:00
|
|
|
use Illuminate\Http\Request;
|
2015-04-22 21:21:04 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Class DuplicateSubmissionCheck.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2015-04-22 21:21:04 +02:00
|
|
|
class DuplicateSubmissionCheck
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @param Request $request
|
|
|
|
* @param Closure $next
|
2017-01-30 20:40:43 +01:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle(Request $request, Closure $next)
|
2015-04-22 21:21:04 +02:00
|
|
|
{
|
2017-07-05 14:56:29 +02:00
|
|
|
if ($request->is('api/v1/*')
|
|
|
|
|| $request->is('save_sidebar_state')
|
|
|
|
|| $request->is('documents')) {
|
2016-02-10 03:05:32 +01:00
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:54:19 +02:00
|
|
|
$path = $request->path();
|
2016-07-03 18:11:58 +02:00
|
|
|
|
2015-04-22 21:21:04 +02:00
|
|
|
if (in_array($request->method(), ['POST', 'PUT', 'DELETE'])) {
|
|
|
|
$lastPage = session(SESSION_LAST_REQUEST_PAGE);
|
|
|
|
$lastTime = session(SESSION_LAST_REQUEST_TIME);
|
2016-07-03 18:11:58 +02:00
|
|
|
|
2018-01-08 10:44:35 +01:00
|
|
|
if ($lastPage == $path && (microtime(true) - $lastTime <= 1.5)) {
|
2015-04-27 14:28:40 +02:00
|
|
|
return redirect('/')->with('warning', trans('texts.duplicate_post'));
|
2015-04-22 21:21:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
session([SESSION_LAST_REQUEST_PAGE => $request->path()]);
|
|
|
|
session([SESSION_LAST_REQUEST_TIME => microtime(true)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
2016-09-11 19:05:59 +02:00
|
|
|
}
|