How to customize registration provided by Flask-security?

折月煮酒 提交于 2019-12-06 10:35:44

You may customize views following these instructions: http://flask-security.readthedocs.org/en/latest/customizing.html

And you may hook into the user registration process using signals: http://flask-security.readthedocs.org/en/latest/api.html#signals

IMPORTANT! Second way is pretty simple. @user_registered.connect_via(app) def user_registered_sighandler(sender, **extra): sender.logger.debug("logger-user_registered_sighandler:", extra) user = extra.get('user') role = user_datastore.find_or_create_role('farmer') user_datastore.add_role_to_user(user,role) db.session.commit() print "print-user_registered_sighandler:", extra

To add a role to a user you have to use flask-security's API:

flask_security.datastore.UserDatastore.add_role_to_user(user, role)

Defninitely you will do this inside your own create_account or similar code. ContextProcessors are used to prepare data before rendering templates. It means that you create or get User and Role objects then call the above API to assign the role to the user. Be more specific if you need further help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!