Cleanup middleware and routes
This commit is contained in:
@@ -35,7 +35,7 @@ class Admin
|
||||
}
|
||||
|
||||
/**
|
||||
* We're verifying that the current user is logged in to Cachet and is an admin level.
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
|
||||
@@ -17,7 +17,7 @@ use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
class ApiAuthenticate
|
||||
class ApiAuthentication
|
||||
{
|
||||
/**
|
||||
* The authentication guard instance.
|
||||
@@ -27,7 +27,7 @@ class ApiAuthenticate
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new api authenticate middleware instance.
|
||||
* Create a new api authentication middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
*
|
||||
@@ -43,19 +43,22 @@ class ApiAuthenticate
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param bool $required
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
public function handle($request, Closure $next, $required = false)
|
||||
{
|
||||
if ($this->auth->guest()) {
|
||||
if ($apiToken = $request->header('X-Cachet-Token')) {
|
||||
try {
|
||||
$this->auth->onceUsingId(User::findByApiToken($apiToken)->id);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
throw new HttpException(401);
|
||||
if ($required) {
|
||||
throw new HttpException(401);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} elseif ($required) {
|
||||
throw new HttpException(401);
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Middleware;
|
||||
|
||||
use CachetHQ\Cachet\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
class ApiOptionalAuthenticate
|
||||
{
|
||||
/**
|
||||
* The authentication guard instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Guard
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new api authenticate middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Guard $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if ($this->auth->guest()) {
|
||||
if ($apiToken = $request->header('X-Cachet-Token')) {
|
||||
try {
|
||||
$this->auth->onceUsingId(User::findByApiToken($apiToken)->id);
|
||||
} catch (ModelNotFoundException $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class Localize
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* Constructs a new localize instance.
|
||||
* Constructs a new localize middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Config\Repository $config
|
||||
*
|
||||
|
||||
@@ -16,14 +16,10 @@ use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class HasSetting
|
||||
class ReadyForUse
|
||||
{
|
||||
/**
|
||||
* Run the has setting middleware.
|
||||
*
|
||||
* We're verifying that the given setting exists in our database. If it
|
||||
* doesn't, then we're sending the user to the setup page so that they can
|
||||
* complete the installation of Cachet on their server.
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
@@ -32,10 +28,8 @@ class HasSetting
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$settingName = $this->getSettingName($request);
|
||||
|
||||
try {
|
||||
if (!Setting::get($settingName)) {
|
||||
if (!Setting::get('app_name')) {
|
||||
return Redirect::to('setup');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
@@ -44,18 +38,4 @@ class HasSetting
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the setting from the request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getSettingName($request)
|
||||
{
|
||||
$actions = $request->route()->getAction();
|
||||
|
||||
return $actions['setting'];
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,10 @@ use CachetHQ\Cachet\Facades\Setting;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
|
||||
class AppIsSetup
|
||||
class SetupAlreadyCompleted
|
||||
{
|
||||
/**
|
||||
* Run the app is setup middleware.
|
||||
*
|
||||
* We're verifying that Cachet is correctly setup. If it is, then we're
|
||||
* redirecting the user to the dashboard so they can use Cachet.
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
@@ -17,7 +17,7 @@ use Illuminate\Support\Facades\Redirect;
|
||||
class SubscribersConfigured
|
||||
{
|
||||
/**
|
||||
* We're verifying that subscribers is both enabled and configured.
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
|
||||
Reference in New Issue
Block a user