diff --git a/app/Http/Middleware/Admin.php b/app/Http/Middleware/Admin.php index 0f664aaa..f2e56c8b 100644 --- a/app/Http/Middleware/Admin.php +++ b/app/Http/Middleware/Admin.php @@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Http\Middleware; use Closure; use Illuminate\Contracts\Auth\Guard; -use Illuminate\Support\Facades\Response; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class Admin { @@ -45,9 +45,7 @@ class Admin public function handle($request, Closure $next) { if (!$this->auth->check() || ($this->auth->check() && !$this->auth->user()->isAdmin)) { - return Response::view('errors.401', [ - 'pageTitle' => trans('errors.unauthorized.title'), - ], 401); + throw new UnauthorizedHttpException(); } return $next($request); diff --git a/app/Http/Middleware/ApiAuthenticate.php b/app/Http/Middleware/ApiAuthenticate.php index bb1eb95e..5f0559f9 100644 --- a/app/Http/Middleware/ApiAuthenticate.php +++ b/app/Http/Middleware/ApiAuthenticate.php @@ -15,6 +15,7 @@ use CachetHQ\Cachet\Models\User; use Closure; use Illuminate\Contracts\Auth\Guard; use Illuminate\Database\Eloquent\ModelNotFoundException; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class ApiAuthenticate { @@ -48,34 +49,19 @@ class ApiAuthenticate if ($this->auth->guest()) { if ($apiToken = $request->header('X-Cachet-Token')) { try { - $user = User::findByApiToken($apiToken); - - $this->auth->onceUsingId($user->id); + $this->auth->onceUsingId(User::findByApiToken($apiToken)->id); } catch (ModelNotFoundException $e) { - return $this->handleError(); + throw new UnauthorizedHttpException(); } - } elseif ($user = $request->getUser()) { + } elseif ($request->getUser()) { if ($this->auth->onceBasic() !== null) { - return $this->handleError(); + throw new AccessDeniedHttpException(); } } else { - return $this->handleError(); + throw new AccessDeniedHttpException(); } } return $next($request); } - - /** - * Common method for returning an unauthorized error. - * - * @return \Symfony\Component\HttpFoundation\Response - */ - protected function handleError() - { - return response()->json([ - 'message' => 'You are not authorized to view this content.', - 'status_code' => 401, - ], 401); - } } diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 2bfc642f..6922ed42 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Http\Middleware; use Closure; use Illuminate\Contracts\Auth\Guard; +use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class Authenticate { @@ -44,11 +45,7 @@ class Authenticate public function handle($request, Closure $next) { if ($this->auth->guest()) { - if ($request->ajax()) { - return response('Unauthorized.', 401); - } else { - return redirect()->guest('auth/login'); - } + throw new UnauthorizedHttpException(); } return $next($request); diff --git a/resources/lang/de/errors.php b/resources/lang/de/errors.php deleted file mode 100755 index 2a5f1505..00000000 --- a/resources/lang/de/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'Die Seite konnte nicht gefunden werden!', - 'message' => 'Entschuldigung, aber die Seite konnte nicht gefunden werden. Überprüfen Sie die URL und versuchen Sie es erneut.', - 'link' => 'Zurück zur Startseite', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Unauthorized', - 'message' => 'Sorry, you need admin privileges to see this page.', - 'link' => 'Return to homepage', - ], -]; diff --git a/resources/lang/en-UD/errors.php b/resources/lang/en-UD/errors.php deleted file mode 100755 index 8d8ce52e..00000000 --- a/resources/lang/en-UD/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => 'crwdns208:0crwdne208:0', - 'title' => 'crwdns367:0crwdne367:0', - 'message' => 'crwdns368:0crwdne368:0', - 'link' => 'crwdns369:0crwdne369:0', - ], - 'unauthorized' => [ - 'code' => 'crwdns370:0crwdne370:0', - 'title' => 'crwdns371:0crwdne371:0', - 'message' => 'crwdns372:0crwdne372:0', - 'link' => 'crwdns373:0crwdne373:0', - ], -]; diff --git a/resources/lang/en/errors.php b/resources/lang/en/errors.php deleted file mode 100755 index 9e13a37d..00000000 --- a/resources/lang/en/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'That page went missing!', - 'message' => 'Sorry, but the page you are looking for has not been found. Check the URL for errors and try again.', - 'link' => 'Return to homepage', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Unauthorized', - 'message' => 'Sorry, you need admin privileges to see this page.', - 'link' => 'Return to homepage', - ], -]; diff --git a/resources/lang/es/errors.php b/resources/lang/es/errors.php deleted file mode 100755 index e0867834..00000000 --- a/resources/lang/es/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => '¡Esta página se perdió!', - 'message' => 'Lo sentimos, no se ha encontrado la página que estás buscando. Comprueba que la dirección URL no contenga errores y vuelve a intentarlo.', - 'link' => 'Regresar a la página de inicio', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'No autorizado', - 'message' => 'Lo sentimos, necesitas privilegios de administrador para ver esta página.', - 'link' => 'Regresar a la página de inicio', - ], -]; diff --git a/resources/lang/fr/errors.php b/resources/lang/fr/errors.php deleted file mode 100755 index 58c89379..00000000 --- a/resources/lang/fr/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'Cette page est manquante !', - 'message' => 'Désolé, mais la page que vous recherchez est introuvable. Vérifier l\'URL et essayez à nouveau.', - 'link' => 'Retour à l\'accueil', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Unauthorized', - 'message' => 'Sorry, you need admin privileges to see this page.', - 'link' => 'Return to homepage', - ], -]; diff --git a/resources/lang/id/errors.php b/resources/lang/id/errors.php deleted file mode 100644 index ba6e430b..00000000 --- a/resources/lang/id/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'Halaman ini hilang!', - 'message' => 'Maaf, halaman yang diinginkan tidak ditemukan. Periksa apakah ada kesalahan URL lalu coba lagi.', - 'link' => 'Kembali ke depan', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Tidak dibolehkan', - 'message' => 'Maaf, anda perlu kewenangan admin untuk melihat halaman ini.', - 'link' => 'Kembali ke depan', - ], -]; diff --git a/resources/lang/nl/errors.php b/resources/lang/nl/errors.php deleted file mode 100755 index 5b73d1ce..00000000 --- a/resources/lang/nl/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'Die pagina is vermist geraakt!', - 'message' => 'Sorry, maar de pagina die je zoekt is niet gevonden. Controleer de URL op fouten en probeer het nogmaals.', - 'link' => 'Terug naar homepagina', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Ongeautoriseerd', - 'message' => 'Sorry, maar je moet beheerdersrechten hebben om deze pagina te bekijken.', - 'link' => 'Terug naar homepagina', - ], -]; diff --git a/resources/lang/pl/errors.php b/resources/lang/pl/errors.php deleted file mode 100755 index 9e13a37d..00000000 --- a/resources/lang/pl/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'That page went missing!', - 'message' => 'Sorry, but the page you are looking for has not been found. Check the URL for errors and try again.', - 'link' => 'Return to homepage', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Unauthorized', - 'message' => 'Sorry, you need admin privileges to see this page.', - 'link' => 'Return to homepage', - ], -]; diff --git a/resources/lang/pt-BR/errors.php b/resources/lang/pt-BR/errors.php deleted file mode 100755 index ba315f3b..00000000 --- a/resources/lang/pt-BR/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => 'Essa página desapareceu!', - 'message' => 'Desculpe, mas a página que você está procurando não foi encontrada. Verifique a URL por erros e tente novamente.', - 'link' => 'Voltar para a página inicial', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => 'Não autorizado', - 'message' => 'Desculpe, que você precisa de privilégios de administrador para ver esta página.', - 'link' => 'Voltar para a página inicial', - ], -]; diff --git a/resources/lang/zh-CN/errors.php b/resources/lang/zh-CN/errors.php deleted file mode 100755 index b40875a0..00000000 --- a/resources/lang/zh-CN/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => '这个页面失踪了!', - 'message' => '抱歉,但我们无法找到您要访问的的页面。请检查你的 URL,然后重试。', - 'link' => '返回主页', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => '未授权', - 'message' => '很抱歉,您需要管理员权限才能看到此页面。', - 'link' => '返回主页', - ], -]; diff --git a/resources/lang/zh-TW/errors.php b/resources/lang/zh-TW/errors.php deleted file mode 100755 index 33df5af8..00000000 --- a/resources/lang/zh-TW/errors.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - 'not-found' => [ - 'code' => '404', - 'title' => '找不到頁面', - 'message' => '抱歉,你所請求的頁面並不存在。請檢查你的 URL 是否正確並再試一次。', - 'link' => '返回主頁', - ], - 'unauthorized' => [ - 'code' => '401', - 'title' => '未經授權', - 'message' => '抱歉,你需要管理員權限方可瀏覽本頁面。', - 'link' => '返回主頁', - ], -]; diff --git a/resources/views/errors/401.blade.php b/resources/views/errors/401.blade.php deleted file mode 100644 index 10f342bb..00000000 --- a/resources/views/errors/401.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -@extends('layout.error') - -@section('content') -
-
- -
-

{{ trans('errors.unauthorized.code') }}

-

{{ trans('errors.unauthorized.title') }}

- -
-

{{ trans('errors.unauthorized.message') }}

-
-

- {{ trans('errors.unauthorized.link') }} -

-
-
-@stop diff --git a/resources/views/errors/404.blade.php b/resources/views/errors/404.blade.php deleted file mode 100644 index 4b484421..00000000 --- a/resources/views/errors/404.blade.php +++ /dev/null @@ -1,19 +0,0 @@ -@extends('layout.error') - -@section('content') -
-
- -
-

{{ trans('errors.not-found.code') }}

-

{{ trans('errors.not-found.title') }}

- -
-

{{ trans('errors.not-found.message') }}

-
-

- {{ trans('errors.not-found.link') }} -

-
-
-@stop