diff options
author | Sam | 2013-05-10 01:31:50 +0000 |
---|---|---|
committer | Sam | 2013-05-10 01:31:50 +0000 |
commit | 8ff6e6a1b7f4e435eb06130b82cce579bcd32dcc (patch) | |
tree | 481f3ad5b6033bb90980a96251a5e8768a06dd69 /wqflask/wqflask/model.py | |
parent | 408802949965f232224b07aee051477d06a30448 (diff) | |
download | genenetwork2-8ff6e6a1b7f4e435eb06130b82cce579bcd32dcc.tar.gz |
Have the beginnings of a user_manager working
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r-- | wqflask/wqflask/model.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/wqflask/wqflask/model.py b/wqflask/wqflask/model.py new file mode 100644 index 00000000..be86ce77 --- /dev/null +++ b/wqflask/wqflask/model.py @@ -0,0 +1,39 @@ +from __future__ import print_function, division, absolute_import + +from flask.ext.sqlalchemy import SQLAlchemy +from flask.ext.security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin + +from wqflask import app + +# Create database connection object +db = SQLAlchemy(app) + +# Define models +roles_users = db.Table('roles_users', + db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), + db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) + +class Role(db.Model, RoleMixin): + id = db.Column(db.Integer(), primary_key=True) + name = db.Column(db.String(80), unique=True) + description = db.Column(db.String(255)) + +class User(db.Model, UserMixin): + id = db.Column(db.Integer(), primary_key=True) + email = db.Column(db.String(255), unique=True) + password = db.Column(db.String(255)) + active = db.Column(db.Boolean()) + confirmed_at = db.Column(db.DateTime()) + + last_login_at = db.Column(db.DateTime()) + current_login_at = db.Column(db.DateTime()) + last_login_ip = db.Column(db.String(39)) + current_login_ip = db.Column(db.String(39)) + login_count = db.Column(db.Integer()) + + roles = db.relationship('Role', secondary=roles_users, + backref=db.backref('users', lazy='dynamic')) + +# Setup Flask-Security +user_datastore = SQLAlchemyUserDatastore(db, User, Role) +security = Security(app, user_datastore) |