I want to do something programatically when user is created.
When user Is there any specific event to subscribe to ? It'd be great if I can do:
<subscriber
for="IUserRegisteredEvent"
handler=".registration.welcome_email"
/>
Also: Is IMemberData correct Interface that represents an user in Plone ? So that I can adapt it and do things like this:
user_activity = IUserActivityStream(member)
user_activity.log(event)
This question is nearly identical to this.
So the correct interface for the subscriber is:
Products.PluggableAuthService.interfaces.events.IPrincipalCreatedEvent
Related
Hi I have a question about symfony application architecture,
In my application I create different user, but when a user is created, updated, deleted, or his picture change, I need to do some action.
What is the best way to do this ? I excluded to do this on a controller action. There is 2 others solutions :
Create differents events like user.created, user.updated, ... And dispatch it on the controller action and make different listener to do the different action like MailListener (for user.created) TaskListener (for user.created) for add a task.
Use a service like UserManager and on this service have a method like userCreated() and on this method call differents actions like sendMailOnCreated, addTaskOnCreated for example.
For you what is the best method ?
For me, your first solution is the best one. It's clearly a use case for the Event component. It will be easier to maintain and more readable.
Moreover, if you need to add more listener you just need to create another one and bind it to your event. You don't need to modify your controller anymore.
I'm new in symfony2 and I'm currently facing a problem. I would like to restrict the access on some of my page based on some dates contained in my database.
For example all the page after my mon.site/home/ would be redirect on an error page. I have already thinking on a event listener, but don't know how to restrict on some URL. Is there a better way to implement this function? If not how can I do it?
It's quite straightforward to me. You can choose between two different solutions
First solution
1) Create a custom event and event subscriber.
2) Dispatch event you've created at 1) everywhere (in every action) you need an extra control
3) Inside the event subscriber call for a method into custom event or directly a method of the subscriber to check if the "request satisfy your needs"
4) Raise an AccessDeniedException.
Second solution
1) With DependencyInjection create a custom configuration where you can specify what controller's actions should be checked for the condition you wish
2) Create an EventListener that listen for kernelRequest event
3) Into EventListener just check for condition
4) Raise an AccessDeniedException.
For restricting access you can use:
voters (and also using different strategies of access decision
manager)
you can also restrict access for whole sections of your app, using
access_control option in your security.yml
you can also use acl
try to avoid using listeners.
P.S. and also if this not enough you can configure .htaccess
I am new to programming. How can I create a custom URL for each user to retrieve data for the entered user? For instance, www.hellothisis.com/sirushti
I understand that it's very difficult in the beginning. However, have you read the introduction to MVC? There you will understand the basics and go further.
Even though you need to read that, the answer to you question is: this
You will see the default router and the "/sirushti" is the ID. In the controller you will likely to have something like this:
public JsonResult GetUser(string alias) { ... }
Take a look on the links I've sent you and you will get what it takes to use MVC!
So we've got SomeBundle and want execute some actions (services\another action from another bundle or something else) before SomeBundleControllerAction will be called. I read that some guys tries it from bundle class, some from event listener (but i can not get in how it works) and now question is.
How to call, proper way, (let it be) service before any of action from our SomeBundle will be called?
I don't like just posting a link, but this pretty much explains what I would do in your case. You can inject your service into the listener anyway you would like (constructor, setter).
http://symfony.com/doc/current/cookbook/event_dispatcher/before_after_filters.html#before-filters-with-the-kernel-controller-event
here was a full description of my answer (some bad person put minus =\ but didn't help at all, next time put links if you know where to find an answer) http://symfony.com/doc/current/book/internals.html#kernel-controller-event
I need to extend a Plone product (Products.Poi) with a second product.
In the extension product i need to override a subscriber event of the original.
I tried to subscribe in an override.zcml an event with the same name but the second event don't override the first but all two are execute.
Here http://plone.org/products/dexterity/documentation/manual/five.grok/core-components/events seem that is not possible:
Unlike adapters, you cannot override an event subscriber by using a more specific interface. Each and every applicable event subscriber will be executed when an event is fired.
Someone has a trick?
Thanks Alex
Simone Orsi gave me a solution: z3c.unconfigure.
This product permit to disable zcml configuration.
To use it, I executed this step on my extented Poi product:
Added "z3c.unconfigure" as install_requires in the setup.py
Create event.py with the new definition of update_tracker_watchers
In the overrides.zcml add this line to unconfigure Products.Poi.events.update_tracker_watchers and to register my new event
<include package="z3c.unconfigure" file="meta.zcml" />
<unconfigure>
<subscriber
for="Products.Poi.interfaces.ITracker
Products.Archetypes.interfaces.IObjectEditedEvent"
handler="Products.Poi.events.update_tracker_watchers"
/>
</unconfigure>
<subscriber
for="Products.Poi.interfaces.ITracker
Products.Archetypes.interfaces.IObjectEditedEvent"
handler=".events.update_tracker_watchers"
/>
When you specified the overrides.zcml, you also need to register the zcml override in buildout? Take a look at: http://developer.plone.org/components/zcml.html?highlight=zcml#overrides It'd be something like: zcml = my.package-overrides
Additionally, you can try using the z3c.unconfigure package: http://pypi.python.org/pypi/z3c.unconfigure