Vorgeschaltete Loginseite

Hallo, wenn ein Besucher den Shop besucht hätte ich gerne, dass er immer zur Logikseite weitergeleitet wird, wenn er nicht angemeldet ist. Wie kann man das am Besten realisieren? Bin Fr jede Hilfe dankbar…

prüfen ob die Session gesetzt wurde und ggf. auf Login redirecten.

schau mal hier: programmierung-f103/user-abfrage-in-bootstrap-php-geht-nicht-t28178.html Freundliche Grüße, Sven

Ich habe es jetzt mal mit einem kleinen Plugin probiert, das bis jetzt nicht funktioniert. Ist mein erstes Plugin. Was mache ich falsch? public function install() { $this-\>subscribeEvent( 'Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Index', 'onPostDispatchIndex' ); return true; } public function uninstall() { return array('success' =\> true, 'invalidateCache' =\> array('frontend')); } public function onPostDispatchIndex(Enlight\_Event\_EventArgs $arguments) { /\*\*@var $controller Shopware\_Controllers\_Frontend\_Index \*/ $controller = $arguments-\>getSubject(); if ($this-\>Application()-\>Session()) { // Kunde ist angemeldet $controller-\>forward('index'); } else { // Kunde nicht angemeldet $controller-\>forward('account'); }

Cache gelöscht? try this if (!empty(Shopware()-\>System()-\>sUserId)) { Weiter ruft ein Besucher nicht zwangsläufig die index auf, dementsprechend Enlight\_Controller\_Action\_PostDispatch\_Frontend\_Index ändern zu Enlight\_Controller\_Action\_PostDispatch\_Frontend

Leider kein Unterschied. Der Shop lädt die Startseite, macht aber keine Weiterleitung zum Login. Das Redirect scheint nicht zu greifen…

[quote]$this->forward()Anchor link for: this forward Will allow you to redirect the request to another controller (action), without actually redirecting the user. Controller forwards will always be handled in the very same request. $this->redirect()Anchor link for: this redirect Will perform a full HTTP redirect with the corresponding status code.[/quote] probier das ganze mal mit $this->redirect() aus :wink:

Bringt leider auch nichts…

probier mal so: private function subscribeEvents() { $this-\>subscribeEvent( 'Enlight\_Controller\_Action\_PreDispatch\_Frontend', 'onFrontendPreDispatch' ); } public function onFrontendPreDispatch(Enlight\_Event\_EventArgs $args) { /\*\* @var \Enlight\_Controller\_Action $controller \*/ $controller = $args-\>get('subject'); /\*\* @var Enlight\_Controller\_Request\_RequestHttp $request \*/ $request = $args-\>get('request'); if ($request-\>getControllerName() == 'register') { return; } if (!Shopware()-\>Modules()-\>Admin()-\>sCheckUser()) { $controller-\>forward('index', 'register'); } } ggfls. muss noch -wie unter http://community.shopware.com/Shopware- … e_Dispatch beschrieben- geprüft werden, dass das Event valide ist

1 „Gefällt mir“

Hallo, ich habe jetzt hinbekommen mit einer kleinen Änderung: private function subscribeEvents() { $this-\>subscribeEvent( 'Enlight\_Controller\_Action\_PreDispatch\_Frontend', 'onFrontendPreDispatch' ); } public function onFrontendPreDispatch(Enlight\_Event\_EventArgs $args) { /\*\* @var \Enlight\_Controller\_Action $controller \*/ $controller = $args-\>get('subject'); /\*\* @var Enlight\_Controller\_Request\_RequestHttp $request \*/ $request = $args-\>get('request'); if (($request-\>getControllerName() == 'register') || ($request-\>getControllerName() == 'account')) { return; } if (!Shopware()-\>System()-\>\_SESSION['sUserId']) { $controller-\>forward('index', 'register'); } }