How can I override the class Mailer on fosuser bundle? - symfony

I have a problem with the ressetting's email of FosUser Bundle because is in txt and I would like to send an email with html form, but the template is a txt template also in the class don't use the 'text/html' option.
So my question is how can I override a internal class (Mailer) of FosUser Bundle (not a controller).

I found the answer in the fosuser docs
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.2.0/Resources/doc/emails.md
"Sending HTML mails"

Related

Symfony Mailer - Migrate addPart from SwiftMailer

I am migrating from SwiftMailer to Symfony Mailer in my application.
How to migrate addPart method of SwiftMailer to Symfony Mailer? In my case the content type is text/plain
->addPart('Plain text content', 'text/plain');
using
swiftmailer 6.1
symfony mailer 4.4
To set the plain text part of your email with Symfony Mailer, you can use
$email->text("...")
See https://symfony.com/doc/current/mailer.html#message-contents for a complete reference
You would just migrate it to
->text('Plain text content')
https://symfony.com/doc/current/mailer.html#message-contents
You can use like this
$email->from($fromEmail)
->to($toEmail)
->html($html_content) /// for html content
->text($text_content) /// for text content
->replyTo($email_info['reply_email'])
->subject($email_info['subject']);
hope this will help. Comment the line if you don't need html content or text content.

Inject custom service into Behat context

Is it possible to build and inject my own, custom services into a Behat Context class?
I'm integrating Behat with Symfony2, and I can inject Symfony's services into my contexts like so:
contexts:
- Meeebu\MyBundle\Features\Security\Context\SecurityContext:
session: '#session'
provided that the Behat\Symfony2Extension is registered.
I'm also using Behat Page Object Extension that injects Page objects into Context constructor directly, so my constructo currently looks like this:
public function __construct(Session $session, Homepage $homepage, WelcomeAdmin $welcomeAdminPage)
Now, I'd like to use my owe custom services in the Context class.
How can I create, register, and inject them in Behat?
you need to create and register a behat extension: https://github.com/Behat/Behat/blob/2.5/src/Behat/Behat/Extension/ExtensionInterface.php
and then register your service (or load an yml/xml/etc. file) in the load method.
and then add an extension class to the behat.yml, to the extensions section.

Symfony2 FosUser override login_check

I'm working with Symfony and FosUserBundle and I need to insert a log in my database if login is ok and before the redirection to my secured area.
I already overrode SecurityController for loginAction, but where can I insert my log ?
I don't think it's in loginAction, but I don't know how can I override login_check ?
Any ideas ?
You can doing the work indirectly with symfony layer framework. If it's good for you that use symfony you can :
use the DefaultAuthenticationSuccessHandler class symfony and read this : DefaultAuthenticationSuccessHandler
declare a service symfony with function 'onAuthenticationSuccess'
After that you can work with all symfony tools for logging all of you want.
I already use this method with FOSUserBundle.

Sonata user bundle creates 4 tables

I have had FosUser bundle before and today installed SonataUserBundle. When I --dump-sql, Symfony wants to install 4 new tables:
fos_user_user
fos_user_group
for_user_user_group
notification_message
First 3 are confusing because admin already works using existing ...Entity\User class for which I even set relations.
namespace Rent\ProgramBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="tbl_user")
*/
class User extends BaseUser
...
Why these 3 tables are installed and how to prevent that? Is there any use for them because admin section is working even without them.
By default, the SonataAdminBundle does not come with any user management, however it is most likely the application requires such feature. The Sonata Project includes a SonataUserBundle which integrates the FOSUserBundle.
The FOSUserBundle adds support for a database-backed user system in Symfony2. It provides a flexible framework for user management that aims to handle common tasks such as user login, registration and password retrieval.
The SonataUserBundle is just a thin wrapper to include the FOSUserBundle into the AdminBundle. The SonataUserBundle includes :
A default login area
A default user_block template which is used to display the current
user and the logout link
2 Admin classes : User and Group
A default class for User and Group.
There is a little magic in the SonataAdminBundle : if the bundle detects the SonataUserBundle class, then the default user_block template will be changed to use the one provided by the SonataUserBundle.
Please take a look to this document. Hope it is helpfull.

Create bundle without default controller and route

Is this possible to create bundle without default controller and route?
Yes, it is. Only required file in the bundle is the bundle class.
Read more in the official documentation: http://symfony.com/doc/current/book/page_creation.html#the-bundle-system

Resources