summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/forms.py4
-rw-r--r--app/login.py12
-rw-r--r--app/model.py25
3 files changed, 13 insertions, 28 deletions
diff --git a/app/forms.py b/app/forms.py
index 182f6de..3bba70e 100644
--- a/app/forms.py
+++ b/app/forms.py
@@ -10,7 +10,7 @@ from wtforms.ext.sqlalchemy.fields import QuerySelectField
import datetime
from . import app
-from .model import User
+from . import login
today = datetime.date.today
@@ -79,7 +79,7 @@ class LoginForm(Form):
if not rv:
return False
- user = User.get_by(name = self.username.data)
+ user = login.User.get_by(name = self.username.data)
if user is None or not user.check_password(self.pwd.data):
return False
diff --git a/app/login.py b/app/login.py
index 6d3fdfa..f4501c8 100644
--- a/app/login.py
+++ b/app/login.py
@@ -1,4 +1,4 @@
-from flask.ext.login import LoginManager
+from flask.ext.login import LoginManager, UserMixin
# just for exporting
from flask.ext.login import login_user, logout_user, login_required, current_user
@@ -6,9 +6,15 @@ from flask.ext.login import login_user, logout_user, login_required, current_use
from passlib.apps import custom_app_context as pwd_context
from . import app
-from .model import User
+from . import model
login_manager = LoginManager()
login_manager.init_app(app)
-login_manager.user_loader(User.get)
+class User (model.User, UserMixin):
+ def check_password(self, pwd):
+ return pwd_context.verify(pwd, self.pwd)
+
+@login_manager.user_loader
+def load_user(id):
+ return User.get(id)
diff --git a/app/model.py b/app/model.py
index ebf3d5b..4c00878 100644
--- a/app/model.py
+++ b/app/model.py
@@ -2,8 +2,6 @@ from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import sql
from sqlalchemy.ext.declarative import declared_attr
-from passlib.apps import custom_app_context as pwd_context
-
import datetime
import decimal
from functools import partial
@@ -51,32 +49,17 @@ class Model (db.Model):
return cls.query.get_or_404(*args, **kwargs)
class User (Model):
+ __abstract__ = True
name = ReqColumn(db.Unicode(50), unique = True)
pwd = ReqColumn(db.Unicode(255))
alias = Column(db.Unicode(50))
- def check_password(self, pwd):
- return pwd_context.verify(pwd, self.pwd)
-
- # Stuff needed for LoginManager
- def is_authenticated(self):
- return True
-
- def is_active(self):
- return True
-
- def is_anonymous(self):
- return False
-
- def get_id(self):
- return unicode(self.id)
-
class UserModel (Model):
__abstract__ = True
@declared_attr
def user_id(cls):
- return ReqColumn(db.Integer, db.ForeignKey(User.id))
+ return ReqColumn(db.Integer, db.ForeignKey('user.id'))
@declared_attr
def user(cls):
@@ -112,10 +95,6 @@ class Expense (UserModel):
expense = ReqColumn(ExpNum)
@declared_attr
- def user_id(cls):
- return ReqColumn(db.Integer, db.ForeignKey(User.id))
-
- @declared_attr
def category_id(cls):
return ReqColumn(db.Integer, db.ForeignKey(Category.id))