mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-28 03:13:26 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			35 lines
		
	
	
		
			1009 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1009 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php namespace app\Http\Middleware;
 | |
| 
 | |
| use Closure;
 | |
| 
 | |
| class DuplicateSubmissionCheck
 | |
| {
 | |
|     // Prevent users from submitting forms twice
 | |
|     public function handle($request, Closure $next)
 | |
|     {
 | |
|         
 | |
|         if ($request->is('api/v1/*')) {
 | |
|             return $next($request);
 | |
|         }
 | |
| 
 | |
|         $path = $request->path();
 | |
|         
 | |
|         if (strpos($path, 'charts_and_reports') !== false) {
 | |
|             return $next($request);
 | |
|         }
 | |
| 
 | |
|         if (in_array($request->method(), ['POST', 'PUT', 'DELETE'])) {
 | |
|             $lastPage = session(SESSION_LAST_REQUEST_PAGE);
 | |
|             $lastTime = session(SESSION_LAST_REQUEST_TIME);
 | |
|             
 | |
|             if ($lastPage == $path && (microtime(true) - $lastTime <= 1)) {
 | |
|                 return redirect('/')->with('warning', trans('texts.duplicate_post'));
 | |
|             }
 | |
| 
 | |
|             session([SESSION_LAST_REQUEST_PAGE => $request->path()]);
 | |
|             session([SESSION_LAST_REQUEST_TIME => microtime(true)]);
 | |
|         }
 | |
| 
 | |
|         return $next($request);
 | |
|     }
 | |
| } |