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.
Related
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
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.
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'.
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.
I'm trying to set up the UserBundle from FOS for symfony 2. When creating a new User, it get an exception that no encoder has been configured.
If I do set up the encoder like this:
fos_user:
db_driver: orm
provider_key: fos_userbundle
class:
model:
user: Crm\MyBundle\Entity\User
group: FOS\UserBundle\Entity\DefaultGroup
encoder:
encode_as_base64: ~
algorithm: ~
iterations: ~
I get a new Exception: InvalidArgumentException.
If I remove iterations and algorithm, the new exception goes away, but then the old "no encoder configured" comes back.
To me it seems as the EncoderFactory in FOS\UserBundle\Security is never used, and the factory from symfony is used instead. I am not sure what to do with this, because frankly I don't know what this "encoder factory" does.
None could help on #symfony (IRC), and I found one other guy having the exact same problem: http://groups.google.com/group/symfony-users/browse_thread/thread/1e0f5797d9357295/d6cd0f7dfc721cbd?show_docid=d6cd0f7dfc721cbd
Thanks
So the problem was that I loaded my bundles in the wrong order... :)
If anyone else get this problem, make sure that this is the order in registerBundles() in AppKernel
new Symfony\Bundle\SecurityBundle\SecurityBundle,
new FOS\UserBundle\FOSUserBundle(),