Appsumo fix

This commit is contained in:
Julien Nahum 2024-01-16 17:40:28 +01:00
parent edfca49b7e
commit 2ffc5311f9
6 changed files with 39 additions and 22 deletions

View File

@ -39,16 +39,10 @@ class Handler extends ExceptionHandler
/** /**
* Convert an authentication exception into a response. * Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/ */
protected function unauthenticated($request, AuthenticationException $exception) protected function unauthenticated($request, AuthenticationException $exception)
{ {
return $request->expectsJson() return response()->json(['message' => $exception->getMessage()], 401);
? response()->json(['message' => $exception->getMessage()], 401)
: redirect(front_url('login'));
} }
public function report(Throwable $exception) public function report(Throwable $exception)

View File

@ -17,10 +17,10 @@ class AppSumoAuthController extends Controller
public function handleCallback(Request $request) public function handleCallback(Request $request)
{ {
$this->validate($request, [ if (!$code = $request->code) {
'code' => 'required', return response()->json(['message' => 'Healthy'], 200);
]); }
$accessToken = $this->retrieveAccessToken($request->code); $accessToken = $this->retrieveAccessToken($code);
$license = $this->fetchOrCreateLicense($accessToken); $license = $this->fetchOrCreateLicense($accessToken);
// If user connected, attach license // If user connected, attach license

View File

@ -30,7 +30,6 @@ class FormSubmissionController extends Controller
public function export(string $id) public function export(string $id)
{ {
$form = Form::findOrFail((int) $id); $form = Form::findOrFail((int) $id);
$this->authorize('view', $form);
$allRows = []; $allRows = [];
foreach ($form->submissions->toArray() as $row) { foreach ($form->submissions->toArray() as $row) {

View File

@ -2,6 +2,7 @@
namespace App\Http; namespace App\Http;
use App\Http\Middleware\AcceptsJsonMiddleware;
use App\Http\Middleware\AuthenticateJWT; use App\Http\Middleware\AuthenticateJWT;
use App\Http\Middleware\CustomDomainRestriction; use App\Http\Middleware\CustomDomainRestriction;
use App\Http\Middleware\IsAdmin; use App\Http\Middleware\IsAdmin;
@ -29,6 +30,7 @@ class Kernel extends HttpKernel
\App\Http\Middleware\SetLocale::class, \App\Http\Middleware\SetLocale::class,
AuthenticateJWT::class, AuthenticateJWT::class,
CustomDomainRestriction::class, CustomDomainRestriction::class,
AcceptsJsonMiddleware::class
]; ];
/** /**

View File

@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class AcceptsJsonMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
$request->headers->set('Accept', 'application/json');
return $next($request);
}
}

View File

@ -24,27 +24,26 @@ export default defineNuxtRouteMiddleware((to, from) => {
const customDomainHeaderValue = useRequestHeaders()[customDomainHeaderName] const customDomainHeaderValue = useRequestHeaders()[customDomainHeaderName]
if (!customDomainHeaderValue || customDomainHeaderValue !== getDomain(getHost())) { if (!customDomainHeaderValue || customDomainHeaderValue !== getDomain(getHost())) {
// If custom domain header doesn't match, redirect return redirectToMainDomain( {
console.error('Custom domain header does not match, redirecting',{ reason: 'header_mismatch',
'customDomainHeaderValue': customDomainHeaderValue, customDomainHeaderValue: customDomainHeaderValue,
'host': getDomain(getHost()),
})
return redirectToMainDomain('header_mismatch', {
customDomainHeaderValue,
host: getDomain(getHost()), host: getDomain(getHost()),
}) })
} }
if (!config.public.customDomainsEnabled) { if (!config.public.customDomainsEnabled) {
// If custom domain not allowed, redirect // If custom domain not allowed, redirect
return redirectToMainDomain('custom_domains_disabled') return redirectToMainDomain({
reason: 'custom_domains_disabled'
})
} }
if (!customDomainAllowedRoutes.includes(to.name)) { if (!customDomainAllowedRoutes.includes(to.name)) {
// Custom domain only allowed for form url // Custom domain only allowed for form url
return redirectToMainDomain('route_not_allowed', { return redirectToMainDomain({
reason: 'route_not_allowed',
route: to.name, route: to.name,
customDomainAllowedRoutes customDomainAllowedRoutes: customDomainAllowedRoutes
}) })
} }
}) })