fosuserbundle

how to add user roles dynamically upon login with symfony2 (and fosUserBundle)?

守給你的承諾、 提交于 2019-11-30 15:59:29
In my app users can switch between free user and premium user over time, when their subscription expires, they no longer have premium previleges. I thought I could cut a corner and not store the premium user role in the database, only store the date to which they have paid, thus eliminating the need for a cron job adding och removing the role premium from my users. The solution I had in mind was to do this on the user entity: public function __construct() { if ( $this->hasPlus() ) { $this->addRole('ROLE_PLUSUSER'); } } Where hasPlus is a function that compares the current date with the paid-to

Sonata User - Security on custom field

℡╲_俬逩灬. 提交于 2019-11-30 15:27:55
I used SonataUser with FOSUser to manage my users and created a custom field company to attach each one to a given company. Now I'd simply need to give users the ability to manage only users attached to the same company: user1 company1 user2 company1 user3 company2 user4 company2 Example: user1 should be able to list/edit only user1 & user2 Should I use ACLs ? Can you point me to the right direction or tutorial to customize SonataUser for this purpose ? Yes ACL is the way to go. create a CompanyVoter implementing VoterInterface and check if the user is on the same company inside it's vote()

Use FOSUserBundle in relation with yml-based Entities

别来无恙 提交于 2019-11-30 14:41:50
I've started a Symfony2 project from scratch where I then installed FOSUserBundle . Then, I have written (actually, generated with ORM Designer) some entities that need to have relations between them, and with the User entity. I have Items belonging to Users , Collections belonging to Users that group Items , and so on. Since I used FOSUserBundle I only have a basic User class ( https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md , step 3a) defined using annotations, no config/doctrine folder and no User.yml file in it. I then created the MyBundle/Resources

FOSUserBundle: Success target after password reset

女生的网名这么多〃 提交于 2019-11-30 12:53:07
问题 After the user did reset his password using the password reset of FOSUserBundle, by default he is redirected to the FOSUserProfile. I want to redirect to a different route. Is this possible and if yes, how? 回答1: It can be done by creating a resetting subscriber: namespace Acme\UserBundle\EventListener; use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Event\FormEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; use

Force a field to not be required

女生的网名这么多〃 提交于 2019-11-30 11:00:40
I am using Symfony2 and FOSUserBundle. Just as detailed in the documentation, I have overridden and created a "name" property in the User entity. I do all necessary and finally get that field to be shown in the form view. The thing is: when I go form_widget(form.name) and the input html tag is generated, a required="required" property is generated within it. And that causes the engine to red the input when the field is not filled in. How do I do to tell the Symfony2 not to make that field mandatory? I guess that it has to be here: parent::buildForm($builder, $options); // add your custom field

FOS UserBundle Unable to login

白昼怎懂夜的黑 提交于 2019-11-30 10:59:34
问题 I'm back with another issue regarding my UserBundle : Everything went perfect while installing and configuring FOS bundle through Symfony2, it even let me create 2 users that were properly inserted into my DB. However, every time I try to login into either of these accounts, I get the following error Warning: Erroneous data format for unserializing 'VillaPrivee\UserBundle\Entity\User' in /Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line

Extends UserManager in Symfony2 with FOSUserBundle

[亡魂溺海] 提交于 2019-11-30 09:53:50
I tried to extend the UserManager of FOS according to this link My service is correctly detected but i have an error i can't resolved : ErrorException: Catchable Fatal Error: Argument 1 passed to FOS\UserBundle\Entity\UserManager::__construct() must be an instance of Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface, none given, called in MyUserManager : namespace ChoupsCommerce\UserBundle\Model; use FOS\UserBundle\Entity\UserManager; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; class MyUserManager extends UserManager { public function

Symfony2 FOSUserBundle – Validate against “user active” flag on login

筅森魡賤 提交于 2019-11-30 09:50:30
I have a flag on my users for 'active' and if set to zero or null, I will not allow login. I have tried a couple of approaches and come up short. If I do the logout route the flash message is not preserved, so the user sees nothing. I looked into adding a validation on the login form so that it would throw a normal form error if the flag was not set to true, but in that folder (vendor/Bundles/FOS/UserBundle/Form/Type) I find nothing for login form, only registration and such, so I wouldn't know where to put it or where to inherit from in order to override. I also tried as suggested here to

Symfony 4 fosuserbundle

会有一股神秘感。 提交于 2019-11-30 08:42:13
I begin with Symfony 4 and I want to install FosUserBundle with this link : https://symfony.com/doc/master/bundles/FOSUserBundle/index.html First : My problem is that I don't know where to find the "app/config/config.yml" file to uncomment the translator and to configure : fos_user: db_driver: orm # other valid values are 'mongodb' and 'couchdb' firewall_name: main user_class: AppBundle\Entity\User from_email: address: "%mailer_user%" sender_name: "%mailer_user%" Second : I think that I have to create the security.yml file in "config/packages/" directory, is that right ? Third : And in which

Symfony2 App with RESTful authentication, using FOSRestBundle and FOSUserBundle

﹥>﹥吖頭↗ 提交于 2019-11-30 07:32:43
I'm making REST API for my JS driven app. During login, the login form is submitted via AJAX to url /rest/login of my API. If the login is succesful, it returns 204 If it fails, it returns 401 While I have separated firewalls for the API and the app itself, they share the same context which should mean, that when user authenticates against the API, he's authenticated against the app too. So, when the server returns 204, page will reload and it should redirect user to the app, because he's now logged in. I tried to use pre-made check_login page of the FOSUserBundle and pointed /rest/login there