Docker compose setup (#513)
* fix password reset bug * self hosted mode middleware changes on pages * fix lint * wip: self hosted changes * wip: self hosted frontend changes * wip self hosted mode changes * typo correction * remove commented logic * fix env variable names * fix lint issues * fix minor updates * #445 Switched from single monolithic docker image to a docker-compose orchestrated network of services * Automatically configures shared secret * Working through some issues * Use local file storage * Moved the dockerfiles * Fixed some issues when building from clean * Corrected workflow * Hopefully schedules everything correctly now * Prep storage for worker process as well * .env files are required * Pinned dependency versions * Disable self hosted in the client as well * Removed double defaulting logic * Using regexs is more succinct * Added FRONT_URL environment variable * Merge 236e4-self-hosted-mode-changes * Improve inital user setup * Finalized the new docker-compose setup * Fix back-end formatting issues --------- Co-authored-by: Frank <csskfaves@gmail.com> Co-authored-by: Don Benjamin <don@webhammer.co.uk>
This commit is contained in:
66
app/Http/Middleware/SelfHostedCredentialsMiddleware.php
Normal file
66
app/Http/Middleware/SelfHostedCredentialsMiddleware.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\User;
|
||||
|
||||
class SelfHostedCredentialsMiddleware
|
||||
{
|
||||
public const ALLOWED_ROUTES = [
|
||||
'login',
|
||||
'credentials.update',
|
||||
'user.current',
|
||||
'logout',
|
||||
];
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (app()->environment('testing')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (in_array($request->route()->getName(), self::ALLOWED_ROUTES)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (
|
||||
config('app.self_hosted') &&
|
||||
$request->user() &&
|
||||
!$this->isInitialSetupComplete()
|
||||
) {
|
||||
return response()->json([
|
||||
'message' => 'You must change your credentials when in self-hosted mode',
|
||||
'type' => 'error',
|
||||
], Response::HTTP_FORBIDDEN);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
private function isInitialSetupComplete(): bool
|
||||
{
|
||||
return (bool) Cache::remember('initial_user_setup_complete', 60 * 60, function () {
|
||||
$maxUserId = $this->getMaxUserId();
|
||||
if ($maxUserId === 0) {
|
||||
return false;
|
||||
}
|
||||
return !User::where('email', 'admin@opnform.com')->exists();
|
||||
});
|
||||
}
|
||||
|
||||
private function getMaxUserId(): int
|
||||
{
|
||||
return (int) Cache::remember('max_user_id', 60 * 60, function () {
|
||||
return User::max('id') ?? 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user