| 
									
										
										
										
											2017-01-16 00:27:24 +08:00
										 |  |  | <?php namespace BookStack\Http\Middleware; | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | use Closure; | 
					
						
							|  |  |  | use Illuminate\Contracts\Auth\Guard; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class RedirectIfAuthenticated | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * The Guard implementation. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var Guard | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     protected $auth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Create a new filter instance. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-09-05 03:40:36 +08:00
										 |  |  |      * @param  Guard $auth | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  |      * @return void | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function __construct(Guard $auth) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->auth = $auth; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Handle an incoming request. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-09-05 03:40:36 +08:00
										 |  |  |      * @param  \Illuminate\Http\Request $request | 
					
						
							|  |  |  |      * @param  \Closure                 $next | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  |      * @return mixed | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function handle($request, Closure $next) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-18 01:22:04 +08:00
										 |  |  |         $requireConfirmation = setting('registration-confirmation'); | 
					
						
							|  |  |  |         if ($this->auth->check() && (!$requireConfirmation || ($requireConfirmation && $this->auth->user()->email_confirmed))) { | 
					
						
							| 
									
										
										
										
											2015-09-05 03:40:36 +08:00
										 |  |  |             return redirect('/'); | 
					
						
							| 
									
										
										
										
											2015-07-13 03:01:42 +08:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $next($request); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |