2015-07-12 21:01:42 +02:00
|
|
|
<?php
|
|
|
|
|
2015-09-10 20:31:09 +02:00
|
|
|
namespace BookStack\Http\Middleware;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Illuminate\Contracts\Auth\Guard;
|
2015-09-10 20:31:09 +02:00
|
|
|
use BookStack\Exceptions\UserRegistrationException;
|
2015-08-31 13:29:48 +02:00
|
|
|
use Setting;
|
2015-07-12 21:01:42 +02:00
|
|
|
|
|
|
|
class Authenticate
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The Guard implementation.
|
|
|
|
*
|
|
|
|
* @var Guard
|
|
|
|
*/
|
|
|
|
protected $auth;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new filter instance.
|
|
|
|
*
|
2015-08-08 21:05:30 +02:00
|
|
|
* @param Guard $auth
|
2015-07-12 21:01:42 +02:00
|
|
|
*/
|
|
|
|
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, Closure $next)
|
|
|
|
{
|
2015-09-05 21:25:57 +02:00
|
|
|
if(auth()->check() && auth()->user()->email_confirmed == false) {
|
|
|
|
return redirect()->guest('/register/confirm/awaiting');
|
|
|
|
}
|
2016-01-16 00:21:47 +01:00
|
|
|
|
2016-03-06 13:55:08 +01:00
|
|
|
if ($this->auth->guest() && !setting('app-public')) {
|
2015-07-12 21:01:42 +02:00
|
|
|
if ($request->ajax()) {
|
|
|
|
return response('Unauthorized.', 401);
|
|
|
|
} else {
|
2015-08-05 22:16:10 +02:00
|
|
|
return redirect()->guest('/login');
|
2015-07-12 21:01:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|