diff --git a/example/app.py b/example/app.py index a1df2d2..3f86072 100644 --- a/example/app.py +++ b/example/app.py @@ -84,7 +84,12 @@ def create_sqlalchemy_app(auth_config=None): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/flask_security_example.sqlite' db = SQLAlchemy(app) - Security(app, SQLAlchemyUserDatastore(db)) + + class UserAccountMixin(): + first_name = db.Column(db.String(120)) + last_name = db.Column(db.String(120)) + + Security(app, SQLAlchemyUserDatastore(db, UserAccountMixin)) @app.before_first_request def before_first_request(): @@ -101,7 +106,12 @@ def create_mongoengine_app(auth_config=None): app.config['MONGODB_PORT'] = 27017 db = MongoEngine(app) - Security(app, MongoEngineUserDatastore(db)) + + class UserAccountMixin(): + first_name = db.StringField(max_length=120) + last_name = db.StringField(max_length=120) + + Security(app, MongoEngineUserDatastore(db, UserAccountMixin)) @app.before_first_request def before_first_request(): diff --git a/flask_security/__init__.py b/flask_security/__init__.py index 0ed3995..49a98bb 100644 --- a/flask_security/__init__.py +++ b/flask_security/__init__.py @@ -256,6 +256,7 @@ class Security(object): """ if app is None or datastore is None: return + # TODO: change blueprint name blueprint = Blueprint('auth', __name__) configured = {} diff --git a/flask_security/datastore/__init__.py b/flask_security/datastore/__init__.py index 2bf605b..ef02910 100644 --- a/flask_security/datastore/__init__.py +++ b/flask_security/datastore/__init__.py @@ -21,8 +21,9 @@ class UserDatastore(object): :param db: An instance of a configured databse manager from a Flask extension such as Flask-SQLAlchemy or Flask-MongoEngine""" - def __init__(self, db): + def __init__(self, db, user_account_mixin=None): self.db = db + self.user_account_mixin = user_account_mixin or object def get_models(self): """Returns configured `User` and `Role` models for the datastore diff --git a/flask_security/datastore/mongoengine.py b/flask_security/datastore/mongoengine.py index 8894a21..7e28c39 100644 --- a/flask_security/datastore/mongoengine.py +++ b/flask_security/datastore/mongoengine.py @@ -41,7 +41,7 @@ class MongoEngineUserDatastore(UserDatastore): name = db.StringField(required=True, unique=True, max_length=80) description = db.StringField(max_length=255) - class User(db.Document, UserMixin): + class User(db.Document, UserMixin, self.user_account_mixin): """MongoEngine User model""" username = db.StringField(unique=True, max_length=255) diff --git a/flask_security/datastore/sqlalchemy.py b/flask_security/datastore/sqlalchemy.py index 5fe3d55..e239b51 100644 --- a/flask_security/datastore/sqlalchemy.py +++ b/flask_security/datastore/sqlalchemy.py @@ -48,7 +48,7 @@ class SQLAlchemyUserDatastore(UserDatastore): self.name = name self.description = description - class User(db.Model, UserMixin): + class User(db.Model, UserMixin, self.user_account_mixin): """SQLAlchemy User model""" id = db.Column(db.Integer, primary_key=True)