2015-04-22 21:21:04 +02:00
|
|
|
<?php namespace app\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class DuplicateSubmissionCheck
|
|
|
|
{
|
|
|
|
// Prevent users from submitting forms twice
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2016-02-10 03:05:32 +01:00
|
|
|
|
|
|
|
if ($request->is('api/v1/*')) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:54:19 +02:00
|
|
|
$path = $request->path();
|
|
|
|
|
|
|
|
if (strpos($path, 'charts_and_reports') !== false) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2015-05-09 20:25:16 +02:00
|
|
|
if ($lastPage == $path && (microtime(true) - $lastTime <= 1)) {
|
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);
|
|
|
|
}
|
|
|
|
}
|