Password resetting > request redirects to login - symfony

config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Portal\UserBundle\Entity\User
registration:
confirmation:
enabled: true
form:
type: Portal\UserBundle\Form\RegistrationType
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
When I click on the password reset button, I am forwarded to the login. Button's Route:
{{ 'resetting.reset.submit'|trans }}
It looks like a bug - I have no special configuration, only this. FOSUserBundle version is v2.1.2.

your route "fos_user_resetting_request" must be able to visit anonymously, check that you do not have any security clause in this route [[example #security("has_role('any')") ]], remember to have this route in a firewall that allows anonymous visits
like:
firewalls:
database_security:
anonymous: ~
pattern: ^/

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.

Resetting password not working symfony 3

I use FOSUserBundle on my symfony 3 project. Evrything is ok but i have ONE problem!!!:-(
when i try reset a password on "I forgot my password", no email sending...Even if, the application redirect user to resetting/check-email view.
Actually i test this on a local server with wamp.
This my configuartion files:
#app/paramaters.yml#
mailer_transport: gmail
mailer_host: smtp.gmail.com
mailer_user: adress#gmail.com
mailer_password: ********
#app/config.yml#
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
#FriendsOfSymfonyBundle Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: MA\UserBundle\Entity\User
from_email:
address: adress#gmail.com
sender_name: Admin
service:
mailer: fos_user.mailer.twig_swift
registration:
confirmation:
from_email:
address: adress#gmail.com
sender_name: Admin
resetting:
email:
from_email:
address: adress#gmail.com
sender_name: Admin
Somebody can help me??please!!
I had solve it changing the mailing transport on parameters.yml to "mail"
mailer_transport: mail

FOSUserBundle how to extend handler correctly

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

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