flask-auth / flaskext / auth / models /

Full commit
import datetime
from sqlalchemy import Column, Integer, String, DateTime
from flaskext.auth import AuthUser

def get_user_class(declarative_base):
    Factory function to create an SQLAlchemy User model with a declarative 
    base (for example db.Model from the Flask-SQLAlchemy extension).
    class User(declarative_base, AuthUser):
        Implementation of User for SQLAlchemy.
        id = Column(Integer, primary_key=True)
        username = Column(String(80), unique=True, nullable=False)
        password = Column(String(120), nullable=False)
        salt = Column(String(80))
        role = Column(String(80))
        created = Column(DateTime(), default=datetime.datetime.utcnow)
        modified = Column(DateTime())

        def __init__(self, *args, **kwargs):
            super(User, self).__init__(*args, **kwargs)
            password = kwargs.get('password')
            if password is not None and not
                self.created = datetime.datetime.utcnow()
                # Initialize and encrypt password before first save.

    return User