I got this working by extending the login.html.twig file in my own login file:
{% extends 'FOSUserBundle:Security:login.html.twig' %}
Question
I've read the guide and after installing, configuring and overriding the default template I can browse to my Login page but only my header and footer show up, there is no login form.
config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: WX\ExchangeBundle\Entity\TblUser
routing.yml:
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /Dashboard
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /SignUp
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /ResetPassword
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
security.yml:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface:
algorithm: bcrypt
cost: 15
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /Login
logout: true
anonymous: true
access_control:
- { path: ^/Login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/SignUp, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/ResetPassword, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/Confirm, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/Dashboard/, role: ROLE_ADMIN }
app\Resources\FOSUserBundle\views\layout.html.twig:
{% extends '::base.html.twig' %}
{% block title %}{% endblock %}
{% block body %}
{% block fos_user_content %}{% endblock fos_user_content %}
{% endblock %}
Controller:
namespace WX\ExchangeBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use JMS\SecurityExtraBundle\Annotation\Secure;
class UserController extends Controller
{
/**
* @Route("/Login", name="wx_exchange_login")
* @Template("WXExchangeBundle:User:login.html.twig")
* User log up - Open to public
* Authenticates users to the system
*/
public function loginAction()
{
return array();
}
/**
* @Route("/Dashboard", name="wx_exchange_dashboard")
* @Template("WXExchangeBundle:User:user.html.twig")
* @Secure(roles="IS_AUTHENTICATED_FULLY")
* Dashboard - secured for authenticated users
* Determines if a user is logged in and redirects them to the user dashboard or login page
*/
public function dashboardAction()
{
return array();
}
}
WXExchangeBundle:User:login.html.twig:
{% extends 'FOSUserBundle::layout.html.twig' %}
{% block title %}Login{% endblock %}
{% block body %}
{% block fos_user_content %}{% endblock fos_user_content %}
{% endblock %}
It's not clear from the documentation if I'm supposed to return something in my Controller action. Is this the problem?
Solution
I got this working by extending the login.html.twig file in my own login file:
{% extends 'FOSUserBundle:Security:login.html.twig' %}
OTHER TIPS
You only need the block
{% block fos_user_content %}{% endblock fos_user_content %}
in your layout.html.yml, not in your base.html.yml.
Also you need to render the template with your return.
/**
* @Route("/Login", name="wx_exchange_login")
* @Template("WXExchangeBundle:User:login.html.twig")
* User log up - Open to public
* Authenticates users to the system
*/
public function loginAction()
{
return $this->render('WXExchangeBundle:User:login.html.twig');
}
instead of returning the array