mirror of
https://github.com/wassname/flask-security.git
synced 2026-06-30 16:40:04 +08:00
Initial idea for specifying a user account mixin for user model
This commit is contained in:
+12
-2
@@ -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():
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user