Two different user_class for fos_user configuration - symfony

I have web site based on Symfony 3.4 and Sonata Admin with SonataNews Bundle, SonataUser bundle etc. Everything works fine.
Now my customer wants web shop, and I choose aimeos for symfony. Now the problem is with users. In fos_user I have:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
#user_class: Sonata\UserBundle\Entity\BaseUser
user_class: Application\Sonata\UserBundle\Entity\User
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)
service:
user_manager: sonata.user.orm.user_manager
from_email:
address: "example#example.com"
sender_name: "My website"
but Aimeos wants configuration like this:
fos_user:
db_driver: orm
user_class: Aimeos\ShopBundle\Entity\FosUser
firewall_name: aimeos_myaccount
from_email:
address: "me#example.com"
sender_name: "Test shop"
different firewall and user_class. If I change this, then there are problems with sonata admin, because some sonata bundles use SonataUserBundle, like News bundle for example. Without user_class: Aimeos\ShopBundle\Entity\FosUser, aimeos doesn't work.
My question is: Is it possible (and how) to tell Aimeos to use SonataUserBundle? Or somehow extend this classes?

Extend the Sonata user entity class and add the code for the additional properties from the Aimeos FosUser entity class

Related

How to authorize custom user from db in Symfony4

I just need to authorize custom user. Without any froms, tokens and etc. I have user entity in my DB.
User class is already configuren it fos_user.yaml:
fos_user:
db_driver: orm
firewall_name: main
from_email:
address: '***#*******.**'
sender_name: '**.****.**'
user_class: App\Entity\User
Is it possible? Somethong like
Authurizer::authorize($userEntity)
Thanks.
Authorization in Symfony done Tokens. To be logged in Symfony's World you'll need to set a Token.
One of the common use cases is "auto login" right after registration.
Take a look at this article -> https://ourcodeworld.com/articles/read/459/how-to-authenticate-login-manually-an-user-in-a-controller-with-or-without-fosuserbundle-on-symfony-3
especially for that part
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
BUT also take a look at symfony's impersonalizaiton => https://symfony.com/doc/current/security/impersonating_user.html
It basically allows you to switch users without filling out forms and knowing users' credentials
Custom Commands for FOSUserBundle are
fos:user:activate
fos:user:change-password
fos:user:create
fos:user:deactivate
fos:user:demote
fos:user:promote
There is no such way to authorize directly as you want it.
You can create a custom command in symfony which accepts username and authenticates a user. Here is a way to create such a command : https://symfony.com/doc/current/console.html
Thanks you, guys! I found the solution here!
How to programmatically login/authenticate a user?
Sorry for wrong or stupid question.

FosUserBundle Confirm Email after registration

I want to do email confirmation after each registration of new user in my website, so when the registration is done the system must redirect him to anther page that tells that he should confirm his email address, and only give access only to users they had an activated mail address.
My config file is:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\User
registration:
confirmation:
from_email: # Use this node only if you don't want the global email address for the confirmation email
address: test#example.com
sender_name: Example sender
enabled: true # change to true for required email confirmation
template: '#FOSUser/Registration/email.txt.twig'
This is the error I am getting:
Type error: Argument 1 passed to FOS\UserBundle\EventListener\EmailConfirmationListener::onRegistrationSuccess() must be an instance of FOS\UserBundle\Event\FormEvent, instance of FOS\UserBundle\Event\GetResponseUserEvent given
EmailConfirmationListener onRegistrationSuccess must be an instance of FormEvent
What you are trying to achieve is something that happens by default. It seems like you changed an eventlistener or made a new one that does not work. Also, in your config file 'template:' does not seem to be in the right place because it does not line up with 'enabled' and 'from_email'.

FosUserBundle don't send email to resset password

I have a simple form to login and reminder password, I overwrite the FOSUser template and everything works fine, but when I want to email the password reminder I do not get it to the mail.
This looks like a swiftmailer and fos configuration in config.yml:
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: AirblogBundle\Entity\User
from_email:
address: "admin#admin.com"
sender_name: "Admin"
resetting:
email:
from_email:
address: noreply#yoursite.com
sender_name: No Reply
token_ttl: 0
After sending the email from the resetting/request path, I get the following information:
An email has been sent to ...#wp.pl. It contains a link you must click to reset your password.
Which seems correct because the address entered in the form has the same ending, but my mailbox does not receive any message.
ps: One more question, how to simply overwrite the Twig template, so the login and reminder of the hymn was on one page? Do you need to overwrite the controller?
Did you configure the needed parameters of SwiftMailerBundle well ?
First of all I suggest you to use Symfony's command to check your swift mailer configuration.
Specify the good arguments to send you a debug mail with reading the help command
php app/console swiftmailer:email:send --help
You should receive a mail on the email address you wrote in command.
After this step you can assume that your mail configuration is good
Reset your forget password request
One important (in the version installed on my project, composer requirement ~2.0) thing to know that is FOSUserBundle don't resend mail if you didn't click on the previous reset link sended BUT he display to you the message that he sended the mail.
If you want to "reset" your password request for a specific user
UPDATE user SET confirmation_token = NULL, password_requested_at = NULL WHERE username = "yourdebugusername"
Extending FOSUserBundle Twig templates
You should read this documentation
Basically you can override all the FOSUserTemplate under vendor/friendsofsymfony/user-bundle/Resources/views
I hope it's help !
For overriding FOSUser twig template looks the Symfony Doc

Symfony 2.8+ LDAP Roles

I have set up the new LDAP system with symfony 2.8+
LDAP but I have a problem with the role. It is stated in the documentation that
# app/config/security.yml
security:
# ...
providers:
app_users:
ldap:
service: app.ldap
base_dn: dc=example,dc=com
search_dn: CN=My User,OU=Users,DC=example,DC=com
search_password: p455w0rd
filter: (sAMAccountName={username})
**default_roles: ROLE_USER**
But I don't know, how it works. I would like to get the user from my LDAP and then give them roles. Is it possible with the new LDAP Sytem within symfony ?
I previously used IMAG/LdapBundle but you can't set your own roles because of a bug never patched which prevent modifications from beiing saved...
It currently is not really possible in the Symfony LDAP component (as of the most current, 3.1). See this open issue.
However, I maintain a bundle that allows this as you can define roles that map to specific LDAP groups: https://github.com/ldaptools/ldaptools-bundle. Dunno if that will help you, but I tried to give it a lot of different configuration options.

multiuser in symfony using fosuserBundle

I have three tables in my database: Simpleuser and Admin and StudentUser, I would like use this 3 table to connect in my symphony app , but I know that with fosuserBundle I should configurate just one table to be able to connect to the application.
I already change the first one using config.yml
here :
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: MyApp\UserBundle\Entity\StudentUser
i'm searching solution that let me log in my symfony application with many users , any one have an idea ?
thank you :)
You can use PUGXMultiuserBundle to handle multiple user classes.

Resources