mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php namespace FireflyIII\Http\Middleware;
 | |
| 
 | |
| use App;
 | |
| use Closure;
 | |
| use Config;
 | |
| use Illuminate\Contracts\Auth\Guard;
 | |
| use Illuminate\Http\Request;
 | |
| use Preferences;
 | |
| use Carbon\Carbon;
 | |
| /**
 | |
|  * Class Authenticate
 | |
|  *
 | |
|  * @codeCoverageIgnore
 | |
|  * @package FireflyIII\Http\Middleware
 | |
|  */
 | |
| class Authenticate
 | |
| {
 | |
| 
 | |
|     /**
 | |
|      * The Guard implementation.
 | |
|      *
 | |
|      * @var Guard
 | |
|      */
 | |
|     protected $auth;
 | |
| 
 | |
|     /**
 | |
|      * Create a new filter instance.
 | |
|      *
 | |
|      * @param  Guard $auth
 | |
|      *
 | |
|      */
 | |
|     public function __construct(Guard $auth)
 | |
|     {
 | |
|         $this->auth = $auth;
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Handle an incoming request.
 | |
|      *
 | |
|      * @param  \Illuminate\Http\Request $request
 | |
|      * @param  \Closure                 $next
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     public function handle(Request $request, Closure $next)
 | |
|     {
 | |
|         if ($this->auth->guest()) {
 | |
|             if ($request->ajax()) {
 | |
|                 return response('Unauthorized.', 401);
 | |
|             } else {
 | |
|                 return redirect()->guest('auth/login');
 | |
|             }
 | |
|         }
 | |
|         // if logged in, set user language:
 | |
|         $pref = Preferences::get('language', 'en');
 | |
|         App::setLocale($pref->data);
 | |
|         Carbon::setLocale($pref->data);
 | |
| 
 | |
|         setlocale(LC_TIME, Config::get('firefly.locales.' . $pref->data));
 | |
| 
 | |
|         return $next($request);
 | |
|     }
 | |
| 
 | |
| }
 |