FOSUserBundle how to extend handler correctly - symfony

It throws this error:
Unrecognized option "handler" under "fos_user.registration.form"
And the files are:
//services.yml
app.form.registration:
class: AppBundle\Form\AccomodationFrontSignUpType
tags:
- { name: form.type, alias: app_user_registration }
app.form.handler.registration:
class: AppBundle\Form\Handler\RegistrationFormHandler
arguments: ["#fos_user.registration.form", "#request", "#fos_user.user_manager", "#fos_user.mailer", "#fos_user.util.token_generator"]
scope: request
public: false
//config.yml
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
group:
group_class: AppBundle\Entity\Group
service:
mailer: swiftmailer.mailer.strato
from_email:
address: webmyhomepage#strato.com
sender_name: myHomepage
registration:
form:
handler: app.form.handler.registration
type: app_user_registration
confirmation:
template: FOSUserBundle:Registration:email.txt.twig
enabled: true
Any help is welcome, thanks

The error means that there is an invalid parameter in your config. The key handler in your config
-> handler: app.form.handler.registration
if you take a look inside the fos user bundle DependencyInjection folder, Configuration.php file, that option does not exist. so its invalid :).
There you can see witch options are available. In my current version of this bundle i have this options available under form: type, name, validation_groups.
Also you can see the default configuration for a bundle with:
php app/console debug:config FOSUserBundle

Related

Symfony 4 fosuserbundle

I begin with Symfony 4 and I want to install FosUserBundle with this link :
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
First :
My problem is that I don't know where to find the "app/config/config.yml" file to uncomment the translator and to configure :
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
Second :
I think that I have to create the security.yml file in "config/packages/" directory, is that right ?
Third :
And in which file to add the route ?
Could you help me, please ? :)
I've resolved the problem followed this:
download FOSUserBundle using composer:
composer require friendsofsymfony/user-bundle "~2.0"
At the end of the installation you will have the following error message :
The child node "db_driver" at path "fos_user" must be configured.
Create your User class
Create src/Entity/User.php as custom user class who extend the FOSUserBundle BaseUser class.
<?php
//src/Entity/User.php
namespace App\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
Configure your application's security.yml
Modify config/packages/security.yaml to setup FOSUserBundle security
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
Configure the FOSUserBundle
Create a new file config/packages/fos_user.yaml for the configuration of FOSUserBundle
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: App\Entity\User
from_email:
address: "vincent#vfac.fr"
sender_name: "vincent#vfac.fr"
Update config/packages/framework.yaml to add templating configuration
framework:
templating:
engines: ['twig', 'php']
Import FOSUserBundle routing
Create config/routes/fos_user.yaml
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
Update your database schema
If not already done, you must create your database
php bin/console doctrine:database:create
Update the schema with the informations from your User class entity
php bin/console doctrine:schema:update --force
At this point, all is installed and configured to use FOSUserBundle in Symfony 4. Run the following command to check if all is ok
composer update
If you don't have any error message, you can test !
You can run the web server to test your application
php bin/console server:start
all tutorial here:
https://vfac.fr/blog/how-install-fosuserbundle-with-symfony-4
This is the solution I found to work.
First:
app/config/config.yml doesn't exist anymore instead the configs have been moved to the config folder. For the FOS User Bundle the correct location: /config/packages/fos_user.yaml. As already noted, use the dev-master version FOSUserBundle, it supports 4(still a little work in progress but good enough).
Second:
You are correct, a simple solution is do a composer require security and the recipe will take care of that for you.
https://symfony.com/doc/current/security.html for more info.
Third:
The default FOS User Bundle routes:
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
More info on the FOS routing (step 6)is helpful
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
Also, I recommend looking at the yaml samples in symfony routing documentation. It may make things a little more clear when configuring the routes with relation to FOS User Bundle.
https://symfony.com/doc/current/routing.html
ok i have same problem and it should be like that
first:as #sean Baharmi says you should create /config/packages/fos_user.yaml and inter configuration like this
fos_user:
db_driver: orm
firewall_name: main
user_class: App\Entity\Users
from_email:
address: "hello#youmail.com"
sender_name: "Sender Name"
then in framework.yaml you should enter following because of FOSUserBundle dependencies
templating:
engines: ['twig', 'php']
also for add routing in /config/rourtes/routes.yaml add
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
then it is ready to work
hope works for you
You can't use FOSUSerBundle on Symfony4 at the moment. Support has not been merged yet. You can follow development here.
If you want to use FOSUserBundle with Symfony4 you can try the patch Ryan provided here.

Sonata User Bundle error on profile edit

I configure a symfony 2.7 installation with the lasted sonata admin and sonata user bundles. My backend work well, also work /profile page, but I'm getting this error in /profile/edit-profile and /profile/edit-authentication :
Unable to find template "MopaBootstrapBundle:Form:fields.html.twig" in SonataUserBundle:ChangePassword:changePassword_content.html.twig at line 2.
this is my config.yml
fos_user:
...
profile:
form:
type: fos_user_profile
handler: fos_user.profile.form.handler.default
name: fos_user_profile_form
validation_groups: [Authentication]
sonata_user:
...
profile: # Profile Form (firstname, lastname, etc ...)
form:
type: sonata_user_profile
handler: sonata.user.profile.form.handler.default
name: sonata_user_profile_form
validation_groups: [Profile]
and some routes:
sonata_user_resetting:
resource: "#SonataUserBundle/Resources/config/routing/sonata_resetting_1.xml"
prefix: /resetting
sonata_user_profile:
resource: "#SonataUserBundle/Resources/config/routing/sonata_profile_1.xml"
prefix: /profile
sonata_user_change_password:
resource: "#SonataUserBundle/Resources/config/routing/sonata_change_password_1.xml"
prefix: /profile
Also look for that template mention in that twig file but I don't see it.
Any help will be apreciated.
Finally I find the solution installing mopa bootsrap bundle and configure it.

Unknown entity namespace in security.yml with custom entities folder in Symfony 2

I have my model entities saved in src/AppBundle/Model/Entity.
You can understand, that i have own custom folder for entities (in model folder).
This is my orm settings in config.yml:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
user:
type: annotation
dir: %kernel.root_dir%/../src/AppBundle/Model/Entity
alias: 'Entity'
prefix: AppBundle\Model\Entity
is_bundle: false
I have a problem with these lines in my security.yml:
providers:
our_db_provider:
entity:
class: AppBundle:User
property: username
# if you're using multiple entity managers
# manager_name: customer
There is some error:
Unknown Entity namespace alias 'AppBundle'.
I don't what ref I have to use (AppBundle:User probably not).
Thank you for your answers.
By default, all Symfony bundles will have a nice alias: XxxBundle (aliasing the NamespaceOfXxxBundle\Entity namespace). As you're bundle doesn't follow this convention and stores it in Model\Entity instead, you have 2 options:
Don't use the alias feature and pass the FQCN: AppBundle\Model\Entity\User
Create a new alias, give it a nice name and use it:
doctrine:
orm:
# ...
mappings:
user:
type: annotation
dir: %kernel.root_dir%/../src/AppBundle/Model/Entity
alias: App # <-- the alias name
prefix: AppBundle\Model\Entity
is_bundle: false
App:User

confirmation email not sent after registration in FOSUserBundle

My project is based on symfony 2.3.19 + lastest version version FOSUserBundle.
Actually, FOSuserBundle is working perfectly. In fact, all functionnalities are working correctly. Now, my goal is to activate the email confirmation when a user registers. For that, I configured my project in this way:
# app/config.yml
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: Minn\UserBundle\Entity\User
registration:
form:
type: minn_user_registration
confirmation:
enabled: true
template: MinnUserBundle:Registration:email.txt.twig
from_email:
address: XXXXXXX#gmail.com
sender_name: XXXXXXX
service:
mailer: fos_user.mailer.twig_swift
Checking this configuration, I get forwarded to /register/check-email with the message I wrote in MinnUserBundle:Registration:email.txt.twig. But no email was sent & no error was returned by symfony.
It there any idea?
Thanks,
It was just an error on SMTP credentials.... Thanks again....

Fr3D LDAP BUNDLE with symfony2

I have integrated FOS BUndle and Fr3d Bundle with symfony2. Here is the bug I have got
MappingException: No mapping file found named 'Acme.UserBundle.Entity.User.php' for class 'Acme\UserBundle\Entity\User'.
Here is my config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Acme\UserBundle\Entity\User
fr3d_ldap:
client:
user:
baseDn: cn=admin, dc=test, dc=local
filter: (&(ObjectClass=Person))
attributes: # Specify ldap attributes mapping [ldap attribute, user object method]
service:
user_manager: fos_user.user_manager # Overrides default user manager
ldap_manager: acme.ldap.ldap_manager # Overrides default ldap manager
Please help me
In your config.yml, you need to update your user_class setting under fos_user...
fos_user:
user_class: YourVendorName\UserBundle\Entity\User
Make sure that the user_class property is pointing to a valid entity in your user bundle (and obviously make sure you have a UserBundle)

Resources