Setting a default role in flask-security

假如想象 提交于 2019-12-03 21:13:29

I fixed it using information from this git issue with this:

@user_registered.connect_via(app)
def user_registered_sighandler(app, user, confirm_token):
    default_role = user_datastore.find_role("User")
    user_datastore.add_role_to_user(user, default_role)
    db.session.commit()

If you have already created a role "User", You can add that role to the user when you create/register the user.

def create_user():
    db.create_all()
    user = user_datastore.create_user(email='my@email.com', password='password')
    default_role = user_datastore.find_role(name="User")
    user_datastore.add_role_to_user(user, default_role)
    db.session.commit()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!