我想使用fosuserbundle功能发送确认电子邮件和检索密码等...但它无法正常工作。我目前在LAMP的dev environment
工作。我认为这可能是一个config.yml问题,但我尝试了一切......
我认为我的config.yml文件必须清理,但我不确定我可以删除什么以及我能做什么。
这是我的方式太大config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "@UserBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
filters:
softdeleteable:
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
enabled: true
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
alias: GedmoLoggable # (optional) it will default to the name set for the mappingmapping
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # (optional) it will default to the name set for the mapping
is_bundle: false
stof_doctrine_extensions:
orm:
default:
softdeleteable: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
#Login using email
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
# FOSUserBundle Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
# Permet de définir quel service de mail utiliser
# On utilise twig_swift pour pouvoir envoyer un email en HTML
service:
mailer: fos_user.mailer.twig_swift
user_manager: pugx_user_manager
# Permet de renseigner le nouveau formulaire d'inscription
registration:
form:
type: app_user_registration
# Permet la validation automatique du compte par envoi d'un email
confirmation:
template: UserBundle:Registration:email.txt.twig
enabled: true
from_email:
address: gauthiercoste@gmail.com
sender_name: Gauthier Coste
resetting:
email:
from_email:
address: gauthiercoste@gmail.com
sender_name: Abracadavrac
pugx_multi_user:
users:
standard_user:
entity:
class: UserBundle\Entity\StandardUser
registration:
form:
type: UserBundle\Form\RegistrationStandardUserType
validation_groups: [Registration, Default]
seller:
entity:
class: UserBundle\Entity\Seller
registration:
form:
type: UserBundle\Form\RegistrationSellerType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: UserBundle:Registration:registerProStep1.html.twig
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
parameters.yml
:
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: null
database_name: xxxxxxxxxx
database_user: root
database_password: xxxxxxxxxx
mailer_transport: gmail
mailer_host: 127.0.0.1
mailer_user: xxxxxxxxxx@gmail.com
mailer_password: xxxxxxxxxx
secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
我的注册过程在我的控制器RegistrationStandardUserController.php
中public function registerAction(Request $request)
{
$em = $this->get('doctrine.orm.entity_manager');
//Form creation based on my user entity
$user = new StandardUser();
$form = $this->createForm(RegistrationStandardUserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user ->setEnabled(true);
$em ->persist($user);
$em ->flush();
if (!$user) {
throw new UsernameNotFoundException("User not found");
} else {
$request->getSession()->getFlashBag()->add('success', 'Félicitation '.$user->getFirstName().', vous êtes inscrit');
$this->authenticateUser($user);
}
}else if($form->isSubmitted() && !$form->isValid()){
$request->getSession()->getFlashBag()->add('error', 'Il y a une erreur dans le formulaire d\'inscription');
}
return $this->render('UserBundle:Registration:register.html.twig', array(
'form' => $form->createView()
));
}
答案 0 :(得分:0)
confirmation mail is triggered by the REGISTRATION_SUCCESS
FosUserBundle
事件。为了发送确认邮件,我不得不:
当控制器被超控时,我们不能忘记分发事件。
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);