mirror of
https://github.com/wassname/flask-security.git
synced 2026-07-16 01:20:15 +08:00
Add the ability to specify additional fields on the user model that can be used for logging in.
This commit is contained in:
@@ -826,3 +826,14 @@ class ConfirmableExtendFormsTest(SecurityTest):
|
||||
def test_send_confirmation(self):
|
||||
r = self._get('/confirm', follow_redirects=True)
|
||||
self.assertIn("My Send Confirmation Email Address Field", r.data)
|
||||
|
||||
|
||||
class AdditionalUserIdentityAttributes(SecurityTest):
|
||||
|
||||
AUTH_CONFIG = {
|
||||
'SECURITY_USER_IDENTITY_ATTRIBUTES': ('email', 'username')
|
||||
}
|
||||
|
||||
def test_authenticate(self):
|
||||
r = self.authenticate(email='matt')
|
||||
self.assertIn('Hello matt@lp.com', r.data)
|
||||
|
||||
@@ -128,17 +128,17 @@ def create_roles():
|
||||
|
||||
|
||||
def create_users(count=None):
|
||||
users = [('matt@lp.com', 'password', ['admin'], True),
|
||||
('joe@lp.com', 'password', ['editor'], True),
|
||||
('dave@lp.com', 'password', ['admin', 'editor'], True),
|
||||
('jill@lp.com', 'password', ['author'], True),
|
||||
('tiya@lp.com', 'password', [], False)]
|
||||
users = [('matt@lp.com', 'matt', 'password', ['admin'], True),
|
||||
('joe@lp.com', 'joe', 'password', ['editor'], True),
|
||||
('dave@lp.com', 'dave', 'password', ['admin', 'editor'], True),
|
||||
('jill@lp.com', 'jill', 'password', ['author'], True),
|
||||
('tiya@lp.com', 'tiya', 'password', [], False)]
|
||||
count = count or len(users)
|
||||
|
||||
for u in users[:count]:
|
||||
pw = encrypt_password(u[1])
|
||||
ds.create_user(email=u[0], password=pw,
|
||||
roles=u[2], active=u[3])
|
||||
pw = encrypt_password(u[2])
|
||||
ds.create_user(email=u[0], username=u[1], password=pw,
|
||||
roles=u[3], active=u[4])
|
||||
ds.commit()
|
||||
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ def create_app(config, **kwargs):
|
||||
|
||||
class User(db.Document, UserMixin):
|
||||
email = db.StringField(unique=True, max_length=255)
|
||||
username = db.StringField(max_length=255)
|
||||
password = db.StringField(required=True, max_length=255)
|
||||
last_login_at = db.DateTimeField()
|
||||
current_login_at = db.DateTimeField()
|
||||
|
||||
@@ -29,6 +29,7 @@ def create_app(config, **kwargs):
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
email = TextField()
|
||||
username = TextField()
|
||||
password = TextField()
|
||||
last_login_at = DateTimeField(null=True)
|
||||
current_login_at = DateTimeField(null=True)
|
||||
|
||||
@@ -32,6 +32,7 @@ def create_app(config, **kwargs):
|
||||
class User(db.Model, UserMixin):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
email = db.Column(db.String(255), unique=True)
|
||||
username = db.Column(db.String(255))
|
||||
password = db.Column(db.String(255))
|
||||
last_login_at = db.Column(db.DateTime())
|
||||
current_login_at = db.Column(db.DateTime())
|
||||
|
||||
Reference in New Issue
Block a user