PUGX / PUGXMultiUserBundle

An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
163 stars 96 forks source link

how to put custom logic on successful registration #6

Closed bartoszrychlicki closed 11 years ago

bartoszrychlicki commented 11 years ago

As controllers look bit diffrent than in FOSUserBundle, how can I put some custom logic after registration process? For example I want to send a e-mail to registered user. Where should I put this and how can I fetch registered user entity before he's logged in.

leopro commented 11 years ago

if you have "confirmation.enabled: true", you can put a hook here

if ($return instanceof RedirectResponse) {
    return $return;
}

(https://github.com/PUGX/PUGXMultiUserBundle/blob/master/Resources/doc/index.md#6-create-your-controllers)

and send an email before the user confirm the registration.

instead if you have "confirmation.enabled: false" you can listen to "security.manual_login" event.

Anyway I will add two events (pre and post) for registration, but not immediately ;-)

bartoszrychlicki commented 11 years ago

Ok, but how to get user object there?

leopro commented 11 years ago

as in every controller that extends Symfony\Bundle\FrameworkBundle\Controller\Controller that implements ContainerAwareInterface, with getUser() that is a wrapper for $this->container->get('security.context')->getToken()->getUser();

or

injectiing the Container to your own class (for example a listener)

or

if you are listening "security.manual_login" you can use getUser() method of ManualLoginEvent

bartoszrychlicki commented 11 years ago

Thanks for replay, but user is not logged right after registration, so I can't use security context, container will not do anything also.

Is there a way to get registered user from registration handler?

leopro commented 11 years ago

yes you are right, so you can get the user from the form.

bartoszrychlicki commented 11 years ago

Any tip on how to do it perhaps? :-)