Hi, I'm new with silex and I'm trying to build a simple login and register system. I wrote a before middleware that checks if a user session variable is set, if it's true it means that user is already logged in, otherwise is not and it must be redirecting to the home page where only a login form is visible.
`<?php
$app->before(function () use($app) {
// Checa si ya existe una sesion 'user' existente en variable
$userisloggedin = is_null($app['session']->get('user')) ? false : true;
//Da valor bool a la variable auth de Silex para saber que mostrar si hay o no una session
$app['twig']->addGlobal('auth',$userisloggedin);
The problem is, when redirects to the home page, the user session is not exists yet, so it's redirecting over and over again to the home page and generates an error which is The page isn't redirecting properly
so I would like to know if it is possible to omit the home route for this middleware or what would be a solution for this. Sorry if my english is not good. Thank you!
Hi, I'm new with silex and I'm trying to build a simple login and register system. I wrote a before middleware that checks if a user session variable is set, if it's true it means that user is already logged in, otherwise is not and it must be redirecting to the home page where only a login form is visible.
`<?php
$app->before(function () use($app) {
// Checa si ya existe una sesion 'user' existente en variable $userisloggedin = is_null($app['session']->get('user')) ? false : true;
//Da valor bool a la variable auth de Silex para saber que mostrar si hay o no una session $app['twig']->addGlobal('auth',$userisloggedin);
if(!$userisloggedin) { return $app->redirect($app["url_generator"]->generate("home")); }
});`
The problem is, when redirects to the home page, the user session is not exists yet, so it's redirecting over and over again to the home page and generates an error which is The page isn't redirecting properly
so I would like to know if it is possible to omit the home route for this middleware or what would be a solution for this. Sorry if my english is not good. Thank you!