aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/model.py
diff options
context:
space:
mode:
authorSam2013-05-10 01:31:50 +0000
committerSam2013-05-10 01:31:50 +0000
commit8ff6e6a1b7f4e435eb06130b82cce579bcd32dcc (patch)
tree481f3ad5b6033bb90980a96251a5e8768a06dd69 /wqflask/wqflask/model.py
parent408802949965f232224b07aee051477d06a30448 (diff)
downloadgenenetwork2-8ff6e6a1b7f4e435eb06130b82cce579bcd32dcc.tar.gz
Have the beginnings of a user_manager working
Diffstat (limited to 'wqflask/wqflask/model.py')
-rw-r--r--wqflask/wqflask/model.py39
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)