update 20.10.2025
This commit is contained in:
parent
8c11130b5d
commit
a939cd51ef
616 changed files with 84821 additions and 4121 deletions
0
app/Http/Middleware/ActiveAccount.php
Executable file → Normal file
0
app/Http/Middleware/ActiveAccount.php
Executable file → Normal file
0
app/Http/Middleware/ActiveShop.php
Executable file → Normal file
0
app/Http/Middleware/ActiveShop.php
Executable file → Normal file
0
app/Http/Middleware/Admin.php
Executable file → Normal file
0
app/Http/Middleware/Admin.php
Executable file → Normal file
23
app/Http/Middleware/Checkout.php
Executable file → Normal file
23
app/Http/Middleware/Checkout.php
Executable file → Normal file
|
|
@ -27,33 +27,33 @@ class Checkout
|
|||
'host' => $request->getHost()
|
||||
]);
|
||||
$instance = 'checkout';
|
||||
if($shopping_instance = ShoppingInstance::where('identifier', $request->route('identifier'))->first()){
|
||||
if ($shopping_instance = ShoppingInstance::where('identifier', $request->route('identifier'))->first()) {
|
||||
//user shop
|
||||
//set Lang
|
||||
\Session::put('locale', $shopping_instance->getLocale());
|
||||
\App::setLocale($shopping_instance->getLocale());
|
||||
$user_shop = $shopping_instance->user_shop;
|
||||
|
||||
if($user_shop && $user_shop->active == 1 && $user_shop->user->isActiveShop()){
|
||||
if ($user_shop && $user_shop->active == 1 && $user_shop->user->isActiveShop()) {
|
||||
Util::setPostRoute('user/');
|
||||
\Session::put('user_shop', $user_shop);
|
||||
\Session::put('user_shop_domain', $shopping_instance->subdomain);
|
||||
\Session::put('user_shop_payment', $shopping_instance->payment);
|
||||
\Session::put('user_shop_identifier', $shopping_instance->identifier);
|
||||
|
||||
if($shopping_instance->auth_user_id){
|
||||
if ($shopping_instance->auth_user_id) {
|
||||
\Session::put('auth_user', $shopping_instance->auth_user);
|
||||
}
|
||||
}
|
||||
if($shopping_instance->back){
|
||||
if ($shopping_instance->back) {
|
||||
\Session::put('back_link', $shopping_instance->back);
|
||||
}
|
||||
\Session::put('new_session', true);
|
||||
Yard::instance($instance)->destroy();
|
||||
//restore yard
|
||||
if($shopping_instance->payment !== 6){
|
||||
if ($shopping_instance->payment !== 6) {
|
||||
Yard::instance($instance)->restore($request->route('identifier'), [], true, $instance);
|
||||
}else{
|
||||
} else {
|
||||
//dont delete shopping instance
|
||||
Yard::instance($instance)->restore($request->route('identifier'), [], false, $instance);
|
||||
}
|
||||
|
|
@ -65,21 +65,20 @@ class Checkout
|
|||
|
||||
Yard::instance($instance)->setUserPriceInfos($shopping_instance->shopping_data['user_price_infos']);
|
||||
Yard::instance($instance)->setShippingCountryWithPrice($shopping_instance->country_id, $is_for);
|
||||
|
||||
if($shopping_instance->payment !== 6){
|
||||
|
||||
if ($shopping_instance->payment !== 6) {
|
||||
//delete shopping instance is not save for restore, payment link
|
||||
ShoppingInstance::where('identifier', $request->route('identifier'))->delete();
|
||||
}
|
||||
|
||||
|
||||
$request->route()->forgetParameter('identifier');
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
// \Session::has('user_shop_identifier')
|
||||
if(\Session::has('user_shop') && Yard::instance($instance)->count() > 0){
|
||||
if (\Session::has('user_shop') && Yard::instance($instance)->count() > 0) {
|
||||
return $next($request);
|
||||
}
|
||||
return redirect(Util::getUserCardBackUrl('/card/show', 'checkout'));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,148 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use App\Services\Util;
|
||||
use App\Models\UserShop;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domain\DomainContext;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class DomainResolver
|
||||
{
|
||||
/**
|
||||
* Behandelt eine eingehende Anfrage, um den Domain-Kontext aufzulösen.
|
||||
*
|
||||
* Diese Middleware ist schlank gehalten. Die Hauptlogik zur Erstellung
|
||||
* des DomainContext befindet sich im DomainServiceProvider, um eine
|
||||
* saubere Trennung der Verantwortlichkeiten zu gewährleisten.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
/** @var DomainContext $context */
|
||||
$context = app(DomainContext::class);
|
||||
// Session-Domain je nach Kontext setzen
|
||||
if ($context->type === 'shop') {
|
||||
Config::set('session.domain', '.'.config('app.domain').config('app.tld_shop'));
|
||||
} else {
|
||||
Config::set('session.domain', '.'.config('app.domain').config('app.tld_care'));
|
||||
}
|
||||
// Wenn der DomainServiceProvider die Domain nicht identifizieren konnte,
|
||||
// leiten wir sicher auf die Hauptdomain um.
|
||||
if ($context->isUnknown()) {
|
||||
// Detailliertes Logging für spätere Analyse
|
||||
if(config('app.debug')){
|
||||
\Log::warning('Unknown domain accessed', [
|
||||
'host' => $request->getHost(),
|
||||
'subdomain' => $context->subdomain,
|
||||
'user_agent' => $request->userAgent(),
|
||||
'ip' => $request->ip(),
|
||||
'referer' => $request->header('referer'),
|
||||
'path' => $request->getPathInfo()
|
||||
]);
|
||||
}
|
||||
// Holt die URL der Hauptdomain vom DomainService und leitet um.
|
||||
$mainUrl = app(\App\Services\DomainService::class)->buildUrl('main');
|
||||
return redirect()->away($mainUrl, 301);
|
||||
}
|
||||
if(config('app.debug')){
|
||||
\Log::debug('DomainResolver: context', [
|
||||
'context' => $context,
|
||||
'subdomain' => $context->subdomain
|
||||
]);
|
||||
}
|
||||
// Für User-Shop-Domains: Validierung und Route-Parameter-Bereinigung
|
||||
if ($context->isUserShop()) {
|
||||
// Validiere UserShop-Berechtigung (bereits im DomainServiceProvider geprüft,
|
||||
// aber zusätzliche Sicherheitsebene)
|
||||
if (!$context->userShop) {
|
||||
\Log::warning('UserShop not found', [
|
||||
'subdomain' => $context->subdomain,
|
||||
'host' => $context->host
|
||||
]);
|
||||
abort(503, 'Shop not available');
|
||||
}
|
||||
|
||||
if (!$context->userShop->active) {
|
||||
\Log::info('UserShop inactive accessed', [
|
||||
'shop_id' => $context->userShop->id,
|
||||
'subdomain' => $context->subdomain
|
||||
]);
|
||||
abort(503, 'Shop temporarily unavailable');
|
||||
}
|
||||
|
||||
if (!$context->userShop->user || !$context->userShop->user->isActiveShop()) {
|
||||
\Log::info('UserShop with expired payment accessed', [
|
||||
'shop_id' => $context->userShop->id,
|
||||
'user_id' => $context->userShop->user_id ?? null,
|
||||
'subdomain' => $context->subdomain
|
||||
]);
|
||||
abort(503, 'Shop access denied');
|
||||
}
|
||||
|
||||
// Entferne subdomain Parameter aus der Route
|
||||
// damit catch-all Routen wie /{site}/{subsite?}/{product_slug?} funktionieren
|
||||
if ($request->route('subdomain')) {
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
}
|
||||
}
|
||||
|
||||
// Richtet den Anwendungskontext für Abwärtskompatibilität ein.
|
||||
$this->setupLegacyContext($context);
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stellt die Kompatibilität mit älteren Teilen der Anwendung her,
|
||||
* die direkt auf Session-Daten oder dynamische Konfigurationen zugreifen.
|
||||
*
|
||||
* @param DomainContext $context
|
||||
*/
|
||||
private function setupLegacyContext(DomainContext $context): void
|
||||
{
|
||||
// TODO: [TECH-DEBT] Diese Methode sollte langfristig entfernt werden.
|
||||
// Alle Teile der Anwendung sollten den DomainContext direkt verwenden.
|
||||
if ($context->userShop) {
|
||||
// Setzt die alten Session-Variablen, die von einigen Views/Controllern erwartet werden.
|
||||
Session::put('user_shop', $context->userShop);
|
||||
Session::put('user_shop_domain', $context->host);
|
||||
\Log::debug('DomainResolver: user_shop gesetzt', ['user_id' => $context->userShop->user_id ?? null]);
|
||||
|
||||
// Setzt die app.url zur Laufzeit, um URL-Generierung in alten Teilen zu ermöglichen.
|
||||
Config::set('app.url', $context->host);
|
||||
|
||||
// Kompatibilität mit der Util-Klasse.
|
||||
Util::setPostRoute('user/');
|
||||
} else {
|
||||
if($context->type === 'main'){
|
||||
Session::forget('user_shop');
|
||||
Session::forget('user_shop_domain');
|
||||
Session::save(); // Sofortige Session-Speicherung
|
||||
\Log::debug('DomainResolver: user_shop entfernt (' . $context->type . ' domain)', ['user_shop' => session('user_shop')]);
|
||||
Config::set('app.url', $context->host);
|
||||
}elseif($context->type === 'shop'){
|
||||
Util::setPostRoute('user/');
|
||||
$user_shop = UserShop::where('slug', 'aloevera')->first();
|
||||
Session::put('user_shop', $user_shop);
|
||||
Session::put('user_shop_domain', $context->host);
|
||||
Session::save(); // Sofortige Session-Speicherung
|
||||
\Log::debug('DomainResolver: user_shop hinzugefügt (' . $context->type . ' domain)', ['user_shop' => session('user_shop')]);
|
||||
|
||||
Config::set('app.url', $context->host);
|
||||
}else{
|
||||
// Für Domains ohne UserShop: Session-Daten sofort löschen
|
||||
// Session::forget('user_shop');
|
||||
// Session::put('user_shop_domain', $context->host);
|
||||
// Session::save(); // Sofortige Session-Speicherung
|
||||
// \Log::debug('DomainResolver: user_shop_domain hinzugefügt (' . $context->type . ' domain)', ['user_shop' => session('user_shop')]);
|
||||
Config::set('app.url', $context->host);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
0
app/Http/Middleware/EncryptCookies.php
Executable file → Normal file
0
app/Http/Middleware/EncryptCookies.php
Executable file → Normal file
0
app/Http/Middleware/Localization.php
Executable file → Normal file
0
app/Http/Middleware/Localization.php
Executable file → Normal file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file → Normal file
0
app/Http/Middleware/RedirectIfAuthenticated.php
Executable file → Normal file
0
app/Http/Middleware/RemoveExcessWhitespaceMiddleware.php
Executable file → Normal file
0
app/Http/Middleware/RemoveExcessWhitespaceMiddleware.php
Executable file → Normal file
255
app/Http/Middleware/SubdomainResolver.php
Normal file
255
app/Http/Middleware/SubdomainResolver.php
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Domain\EarlyDomainParser;
|
||||
use App\Models\UserShop;
|
||||
use App\Services\Util;
|
||||
use Closure;
|
||||
use Config;
|
||||
use Session;
|
||||
|
||||
/**
|
||||
* Lightweight subdomain resolution middleware
|
||||
*
|
||||
* Uses config/domains.php for domain configuration and provides
|
||||
* simple, working subdomain handling without session timing issues.
|
||||
*/
|
||||
class SubdomainResolver
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// Skip for API and asset requests
|
||||
if (!$this->shouldProcess($request)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// Parse domain information using config/domains.php
|
||||
$host = $request->getHost();
|
||||
$domainInfo = EarlyDomainParser::parseDomain($host);
|
||||
Session::put('domainInfo', $domainInfo);
|
||||
\Log::info('domainInfo', $domainInfo);
|
||||
// Route to appropriate handler based on domain type
|
||||
return match ($domainInfo['type']) {
|
||||
'user-shop' => $this->handleUserShop($request, $next, $domainInfo),
|
||||
'main-shop' => $this->handleMainShop($request, $next, $domainInfo),
|
||||
'main' => $this->handleMainCare($request, $next, $domainInfo),
|
||||
'crm' => $this->handleCrm($request, $next, $domainInfo),
|
||||
'portal' => $this->handlePortal($request, $next, $domainInfo),
|
||||
'checkout' => $this->handleCheckout($request, $next, $domainInfo),
|
||||
default => $this->handleUnknownDomain($request, $domainInfo),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle user shop subdomain (e.g., user.mivita.care)
|
||||
*/
|
||||
private function handleUserShop($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
$subdomain = $domainInfo['subdomain'];
|
||||
$userShop = UserShop::where('slug', $subdomain)->first();
|
||||
|
||||
// Remove subdomain parameter from route
|
||||
if ($request->route('subdomain')) {
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
}
|
||||
|
||||
if (!$userShop) {
|
||||
return $this->handleUnknownDomain($request, $domainInfo);
|
||||
}
|
||||
|
||||
// Validate shop status
|
||||
if (!$userShop->active || !$userShop->user || !$userShop->user->isActiveShop()) {
|
||||
//hier ein routing zu shop???
|
||||
abort(503, 'Shop temporarily unavailable');
|
||||
}
|
||||
$host = $this->getHost($domainInfo);
|
||||
// Configure session domain based on domain config
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Set up application context
|
||||
$this->setupUserShopContext($userShop, $subdomain, $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle main shop domain (e.g., mivita.shop)
|
||||
*/
|
||||
private function handleMainShop($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Load default shop from domain config
|
||||
$defaultShop = isset($domainInfo['default_user_shop']) ? $domainInfo['default_user_shop'] : 'aloevera';
|
||||
$userShop = UserShop::where('slug', $defaultShop)->first();
|
||||
|
||||
// Configure session domain based on domain config, not getHost only for care domains
|
||||
$host = isset($domainInfo['host']) ? $domainInfo['host'] : config('app.domain') . config('app.tld_shop');
|
||||
Config::set('session.domain', '.' . $host);
|
||||
|
||||
if ($userShop) {
|
||||
\Session::put('user_shop', $userShop);
|
||||
\Session::put('user_shop_domain', config('app.protocol') . $host);
|
||||
Util::setPostRoute('user/');
|
||||
Config::set('app.url', $host);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle main care domain (e.g., mivita.care)
|
||||
*/
|
||||
private function handleMainCare($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain based on domain config
|
||||
$host = $this->getHost($domainInfo);
|
||||
$host = isset($domainInfo['host']) ? $domainInfo['host'] : config('app.domain') . config('app.tld_care');
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Clear any existing shop session data, not needed for main care domain
|
||||
Session::forget('user_shop');
|
||||
Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle CRM domain (e.g., my.mivita.care)
|
||||
*/
|
||||
private function handleCrm($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for CRM
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Clear shop data for CRM , not needed for crm domain
|
||||
Session::forget('user_shop');
|
||||
Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
\Log::info('Session all', Session::all());
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Portal domain (e.g., in.mivita.care)
|
||||
*/
|
||||
private function handlePortal($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for Portal
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Don't clear user_shop - checkout needs to know which shop
|
||||
// Session::forget('user_shop');
|
||||
// Session::forget('user_shop_domain');
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Checkout domain (e.g., checkout.mivita.care)
|
||||
*/
|
||||
private function handleCheckout($request, Closure $next, array $domainInfo)
|
||||
{
|
||||
// Configure session domain for Checkout
|
||||
$host = $this->getHost($domainInfo);
|
||||
$this->configureSessionDomain($host);
|
||||
|
||||
// Keep existing shop session data for checkout
|
||||
// Don't clear user_shop - checkout needs to know which shop
|
||||
|
||||
// Set app URL
|
||||
Config::set('app.url', $host);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle unknown domains
|
||||
*/
|
||||
private function handleUnknownDomain($request, array $domainInfo)
|
||||
{
|
||||
// Redirect to main domain
|
||||
$mainDomain = config('domains.domains.main.host');
|
||||
$mainUrl = config('domains.protocol') . $mainDomain;
|
||||
|
||||
return redirect()->away($mainUrl, 301);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up user shop context in session and config
|
||||
*/
|
||||
private function setupUserShopContext(UserShop $userShop, ?string $subdomain = null, string $host = '')
|
||||
{
|
||||
// Put shop data in session
|
||||
Session::put('user_shop', $userShop);
|
||||
|
||||
// Build shop domain URL using protocol from config
|
||||
$shopDomain = config('domains.protocol') . $host;
|
||||
//$shopDomain = config('app.protocol').$user_shop->slug.".".config('app.domain').config('app.tld_care'));
|
||||
Session::put('user_shop_domain', $shopDomain);
|
||||
|
||||
// Set app URL for URL generation
|
||||
Config::set('app.url', rtrim($shopDomain, '/'));
|
||||
|
||||
// Set post route for compatibility
|
||||
Util::setPostRoute('user/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure session domain based on host
|
||||
*/
|
||||
private function configureSessionDomain(string $host): void
|
||||
{
|
||||
Config::set('session.domain', '.' . config('app.domain') . config('app.tld_care'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get host from domain info
|
||||
*/
|
||||
private function getHost(array $domainInfo): string
|
||||
{
|
||||
if (isset($domainInfo['host'])) {
|
||||
return $domainInfo['host'];
|
||||
}
|
||||
abort(503, 'Host not found in domain info');
|
||||
//throw new \Exception('Host not found in domain info');
|
||||
}
|
||||
/**
|
||||
* Check if request should be processed by this middleware
|
||||
*/
|
||||
private function shouldProcess($request): bool
|
||||
{
|
||||
// Skip API requests
|
||||
if ($request->is('api/*')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip asset requests
|
||||
if ($request->isMethod('GET') && preg_match('/\.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$/i', $request->path())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Skip Laravel internal requests
|
||||
if ($request->is('_debugbar/*')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
0
app/Http/Middleware/SuperAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SuperAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SysAdmin.php
Executable file → Normal file
0
app/Http/Middleware/SysAdmin.php
Executable file → Normal file
0
app/Http/Middleware/TrimStrings.php
Executable file → Normal file
0
app/Http/Middleware/TrimStrings.php
Executable file → Normal file
0
app/Http/Middleware/TrustProxies.php
Executable file → Normal file
0
app/Http/Middleware/TrustProxies.php
Executable file → Normal file
0
app/Http/Middleware/VerifyCsrfToken.php
Executable file → Normal file
0
app/Http/Middleware/VerifyCsrfToken.php
Executable file → Normal file
Loading…
Add table
Add a link
Reference in a new issue