Hello,
I'm trying without success to override a behavior of Flask-Security: sending confirmation emails. I would like them to be sent to a default e-mail address, whatever the candidate user submitted. So that the administrator can review and filter who's registering.
It seems the confirmation email is sent by flask.ext.security.registerable.register_user()
def new_register_user(**kwargs):
# Define a method with new behavior
...
import sys
# Override registerable module method
import flask.ext.security.registerable
sys.modules['flask.ext.security.registerable'].register_user = new_register_user
sys.modules['flask.ext.security'].registerable.register_user = new_register_user
# When printing sys.modules, it seems that registerable module
# appears also there:
import flask_security
sys.modules['flask_security.registerable'].register_user = new_register_user
sys.modules['flask_security'].registerable.register_user = new_register_user
Unfortunately, it does not work. The original method is still used. Do you have any hints?
There's a much easier way to do this.
SEND_REGISTER_EMAIL = Falseflask_security.signals.user_registered signalOtherwise I would not support overriding methods the way you have described.
Thanks for the prompt reply!
Excellent, it worked well :-) Great design!
It isn't very well documented but you can also attach your own callback to the send_mail_task function on the flask_security.core.Security object and it will execute instead of the flask_mail version
security = Security(app, user_datastore)
security.send_mail_task(my_send_email)
Thank you for posting the override functionality! Was just what I needed! Would be great to have this in the docs
The feature mentioned by @Trii is documented (a little) here: https://flask-security.readthedocs.io/en/latest/customizing.html#emails.
Most helpful comment
The feature mentioned by @Trii is documented (a little) here: https://flask-security.readthedocs.io/en/latest/customizing.html#emails.