我希望在User
模型中添加一个字段,使用户可以通过username
而不是email
登录。
我定义了:
app.config['SECURITY_USER_IDENTITY_ATTRIBUTES'] = 'username'
但是我仍然得到以下结果:
user_datastore.add_role_to_user(name, 'mgmt')
File "/Users/boazin/sentinal/sentinel-cloud/.env/lib/python2.7/site-packages/flask_security/datastore.py", line 105, in add_role_to_user
user, role = self._prepare_role_modify_args(user, role)
File "/Users/boazin/sentinal/sentinel-cloud/.env/lib/python2.7/site-packages/flask_security/datastore.py", line 72, in _prepare_role_modify_args
user = self.find_user(email=user)
File "/Users/boazin/sentinal/sentinel-cloud/.env/lib/python2.7/site-packages/flask_security/datastore.py", line 203, in find_user
return self.user_model.query.filter_by(**kwargs).first()
File "/Users/boazin/sentinal/sentinel-cloud/.env/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 1333, in filter_by
for key, value in kwargs.items()]
File "/Users/boazin/sentinal/sentinel-cloud/.env/lib/python2.7/site-packages/sqlalchemy/orm/base.py", line 383, in _entity_descriptor
(description, key)
InvalidRequestError: Entity '<class 'flask_app.models.User'>' has no property 'email'
看起来电子邮件已经硬编码到Flask-Security中了...
我能改变它吗?
编辑: 用户模型(根据评论请求):
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(255), unique=True, index=True)
password = db.Column(db.String(255))
token = db.Column(db.String(255), unique=True, index=True)
active = db.Column(db.Boolean())
confirmed_at = db.Column(db.DateTime())
roles = db.relationship('Role', secondary=roles_users,
backref=db.backref('users', lazy='dynamic'))