Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 user management, use FOSUserBundle or roll my own using the Symfony cookbook code as a starting point?

Tags:

php

symfony

I am familiarizing myself with Symfony 2, after using Symfony 1.x for a few years.

I need to create a membership website that has a custom registration process. Additionally, the website dynamically generates user roles (formerly credentials in SF v1.x) to use to restrict access to portions of the site.

I have had a look at the FOSUserBundle and I can't see what it is offering over and above the code that is available on the 'How to load users from a database' link in the cookbook. I have a lot of custom logic involved in my user registration and user management, as I mentioned earlier, and I don't want to undergo a learning curve of using FOSUserBundle only to have to override a lot of the methods etc, with my own custom methods.

I don't know enough about Symfony2 to make the decision as to whether to learn from the cookbook code and extend it in my own UserBundle, or invest time learning how to use the FOSUserBundle and customize it with my custom logic.

In summary this is what I want to do with users:

  1. Provide a custom registration workflow
  2. Dynamically update a users role/group membership (initially during login, and subsequently, during the session).

My question then is - which course requires the minimum learning curve and effort for me (I have less than a week to get a barebones site up and running - and I'm only doing web development in my spare time).

Do I:

  • Write my own UserBundle, using the code in the cookbook as a starting point
  • Learn how to use FOSUserBundle and customize it with my custom logic? (see above)
like image 452
Homunculus Reticulli Avatar asked Aug 10 '12 10:08

Homunculus Reticulli


2 Answers

It's an old subject but still very interesting nowadays. I disagree with Florent's answer, because i think it doesn't provide an objective view.

FOSUserBundle provides User and Group implementations, just as Symfony already provide, that you just need to configure. The cookbook and the official doc will allow you to get that working in less than a day.

The "full of features" controllers are interesting... as long as you stay in the way defined by this bundle. Don't be too original or you'll spend days overriding code and config of the bundle. Honestly, registration and lost password are easy to implements, and SF2 form's mechanism already make it easy to handle errors.

Views are minimalistic and uninteresting out of the box in FOSUserBundle, make your own ones.

If i had to compare both learning curves i would just sum it up like this : both take the same time to achieve a complex user management system, but you'll be much more in control of your code when writing your own provider.

Would be interesting, 2 years later, to know what choice you made and how it went, Homunculus Reticulli.

like image 159
Ninj Avatar answered Nov 15 '22 16:11

Ninj


FOSUserBundle provides:

  • User and Group implementations
  • controllers with useful features (registration, lost password)
  • views

If you need these features, use this bundle, it will save your time!

I don't know how complex is your authentication logic but I'm pretty sure that it can fit with FOSUserBundle's one.

like image 27
Florent Avatar answered Nov 15 '22 15:11

Florent