here my problem : I have two categories of users in my application (locataires and propriétaires), and i need one (or two) login form. I use PUGXMultiUserBundle to manage all my users.
here is the view for loggin "proprietaires" :
{% extends "::layout.html.twig" %}
{% block title %}
Nous contacter - {{ parent() }}
{% endblock %}
{# Contents #}
{% block body %}
<div class="row">
<div class="col-md-12">
<div class="well">
<form action="{{ path('proprietaire_login_check') }}" method="post">
<fieldset>
<legend><i class="fa fa-lock"></i> Secure Sign in</legend>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="_username" value="" class="form-control"/>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="_password" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">
<i class="fa fa-sign-in"></i> Sign in
</button>
</fieldset>
</form>
</div>
</div>
</div>
{% endblock %}
My file app/config/config.yml :
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
service:
user_manager: pugx_user_manager
pugx_multi_user:
users:
proprietaire:
entity:
class: AppBundle\Entity\Proprietaire
# factory:
registration:
form:
type: AppBundle\Form\Type\RegistrationProprietaireFormType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: proprietaire.form.html.twig
profile:
form:
type: AppBundle\Form\Type\ProfileProprietaireFormType
name: fos_user_profile_form
validation_groups: [Profile, Default]
locataire:
entity:
class: AppBundle\Entity\Locataire
registration:
form:
type: AppBundle\Form\Type\RegistrationLocataireFormType
template: locataire.form.html.twig
profile:
form:
type: AppBundle\Form\Type\ProfileLocataireFormType
And my file app/config/security.yml :
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
FOS\UserBundle\Model\UserInterface: sha512
# http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_manager
proprietaire:
entity:
class: AppBundle:Proprietaire
property: username
locataire:
entity:
class: AppBundle:Locataire
property: username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
# form_login:
# provider: fos_userbundle
# csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
# logout:
# path: /logout
# target: /
anonymous: true
proprietaire_firewall:
pattern: .*
form_login:
# Soumet le formulaire de connection ici
provider: fos_userbundle
check_path: /proprietaire_login_check
logout:
path: /proprietaire_logout
target: /
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profile, role: ROLE_USER }
I begin with symfony 2, and I don't understand how to create a login form for the users "proprietaires" and one other for the users "locataires". And how to configure the differents firewalls in the the file security.yml ?
Another question : in your opinion, I have to create differents "roles" in my security.yml file ?
Thanks very much.