Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private campaign error page #997

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Exceptions;

use App\Facades\Domain;
use App\Models\Campaign;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -57,6 +58,19 @@ public function render($request, Throwable $exception)
} elseif ($exception instanceof AuthorizationException && auth()->guest()) {
// User needs to be logged in, remember the page they visited
session()->put('login_redirect', $request->getRequestUri());
} elseif (!$request->is('api/*') && $exception instanceof ModelNotFoundException) {
// If the guest user tries accessing a private campaign, let's tell them about it
$campaign = request()->route('campaign');
if (empty($campaign) || !($campaign instanceof Campaign)) {
session()->put('login_redirect', $request->getRequestUri());
/** @var Campaign $campaign */
$campaign = Campaign::select('id')->slug($campaign)->first();
if ($campaign && !$campaign->isPublic()) {
return response()->view('errors.private-campaign', [
'campaign' => $campaign
], 200);
}
}
} elseif ($exception instanceof SymHttpException && $exception->getStatusCode() == 503) {
if (request()->ajax()) {
return response()->json([
Expand All @@ -76,7 +90,6 @@ public function render($request, Throwable $exception)
// API error handling
return $this->handleApiErrors($exception);
}

return parent::render($request, $exception);
}

Expand Down
13 changes: 12 additions & 1 deletion lang/en/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
'title' => 'Maintenance',
],
'footer' => 'If you need further assistance, please contact us at :email or on the :discord',
'log-in' => 'Login in to your account might reveal what you are looking for.',
'log-in' => 'Logging in to your account might reveal what you are looking for.',
'post_layout' => 'Invalid post layout.',
'back-to-campaigns' => 'Go back to one of your campaigns',
'private-campaign' => [
'title' => 'Private campaign',
'auth' => [
'helper' => 'You don\'t have access to this campaign.',
],
'guest' => [
'helper' => 'The campaign you are trying to access is private and you are not logged in.',
'login' => 'Logging in might let you access the contents.',
],
],
];
20 changes: 20 additions & 0 deletions resources/views/errors/private-campaign.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@extends('layouts.error', [
'error' => 403
])

@section('content')
<h2>{{ __('errors.private-campaign.title') }}</h2>
@guest
<p class="lg:max-w-2xl mx-auto text-center">
{{ __('errors.private-campaign.guest.helper') }}
</p>
<p class="lg:max-w-2xl mx-auto text-center">
<a href="{{ route('login') }}" class="btn-round rounded-full">{{ __('errors.private-campaign.guest.login') }}</a>
</p>
@else
<p class="lg:max-w-2xl mx-auto text-center">
{{ __('errors.private-campaign.auth.helper') }}
</p>
@endguest

@endsection
40 changes: 17 additions & 23 deletions resources/views/layouts/error.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta property="og:title" content="{{ $title ?? __('front.meta.title', ['kanka' => config('app.name')]) }} - {{ config('app.name') }}" />
<meta property="og:site_name" content="{{ config('app.site_name') }}" />

<title>{{ $error }} - {{ config('app.name', 'Kanka') }}</title>
<title>{{ $error }} {{ __('errors.' . $error . '.title') }} - {{ config('app.name', 'Kanka') }}</title>

<meta name="csrf-token" content="{{ csrf_token() }}">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
Expand Down Expand Up @@ -48,19 +48,23 @@
@include('layouts.front.nav', ['minimal' => $error === 503])
<section class="bg-purple text-white gap-16" id="error-{{ $error }}">
<div class="px-6 py-20 lg:max-w-7xl mx-auto text-center flex flex-col gap-8">
<h2>{{ __('errors.' . $error . '.title') }}</h2>
@if (is_array(__('errors.' . $error . '.body')))
@foreach (__('errors.' . $error . '.body') as $text)
<p class="lg:max-w-2xl mx-auto text-center">{{ $text }}</p>
@endforeach
@hasSection('content')
@yield('content')
@else
<p class="lg:max-w-2xl mx-auto text-center">{{ __('errors.' . $error . '.body') }}</p>
<h2>{{ __('errors.' . $error . '.title') }}</h2>
@if (is_array(__('errors.' . $error . '.body')))
@foreach (__('errors.' . $error . '.body') as $text)
<p class="lg:max-w-2xl mx-auto text-center">{{ $text }}</p>
@endforeach
@else
<p class="lg:max-w-2xl mx-auto text-center">{{ __('errors.' . $error . '.body') }}</p>
@endif

@guest
<p class="lg:max-w-2xl mx-auto text-center">{{ __('errors.log-in') }}</p>
@endguest
@endif

@guest
<p class="lg:max-w-2xl mx-auto text-center">{{ __('errors.log-in') }}</p>
@endguest

<p class="lg:max-w-2xl mx-auto text-center">
{!! __('errors.footer', [
'discord' => '<a href="' . config('social.discord') . '" class="link-light">Discord</a>',
Expand All @@ -72,10 +76,9 @@

<section class="lg:max-w-7xl mx-auto flex flex-col gap-10 lg:gap-10 py-10 lg:py-12 px-4 xl:px-0 text-dark text-center" >
@if ($error !== 503 && auth()->check() && !\App\Facades\Identity::isImpersonating())
<p class="">Go back to one of your campaigns</p>
<div class="flex flex-wrap justify-center items-center gap-10">
<p class="text-md">{{ __('errors.back-to-campaigns') }}</p>
<div class="flex flex-wrap justify-center items-center gap-10 max-w-3xl mx-auto">

<?php /** @var \App\Models\Campaign $campaign */?>
@foreach (auth()->user()->campaigns as $campaign)
<a href="{{ route('dashboard', $campaign) }}" class="btn-round rounded flex gap-2 items-center">
<x-icon class="fa-solid fa-arrow-right" />
Expand All @@ -86,15 +89,6 @@
@endif
</section>

@if ($error === 404)
<section class="max-w-2xl mx-auto flex flex-col gap-10 lg:gap-10 py-10 lg:py-12 px-4 xl:px-0 text-dark">
<img src="/images/errors/lost.jpeg" alt="Lost construction kobolds in a swamp" class="rounded-2xl" />
</section>
@endif

<div id="main-content"></div>
@yield('content')

@includeWhen(Route::has('home'), 'front.footer')
@vite('resources/js/front.js')
@if (config('fontawesome.kit'))
Expand Down
Loading