diff options
author | rubenwardy <rw@rubenwardy.com> | 2020-01-19 19:48:41 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2020-01-19 19:48:41 +0000 |
commit | e115b0678cce0f918e1985524751f95c21dd2b2d (patch) | |
tree | 601e7b08c007d253bb2cf379f313c640ccb0e7e4 /app/models.py | |
parent | 0bda16de6dae7a684acf4332312765fe2d78741c (diff) | |
download | cheatdb-e115b0678cce0f918e1985524751f95c21dd2b2d.tar.xz |
Fix password issues caused by Flask-User migration
Diffstat (limited to 'app/models.py')
-rw-r--r-- | app/models.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models.py b/app/models.py index 1ff2904..69eca7c 100644 --- a/app/models.py +++ b/app/models.py @@ -146,7 +146,7 @@ class User(db.Model, UserMixin): tokens = db.relationship("APIToken", backref="owner", lazy="dynamic") replies = db.relationship("ThreadReply", backref="author", lazy="dynamic") - def __init__(self, username, active=False, email=None, password=None): + def __init__(self, username, active=False, email=None, password=""): self.username = username self.email_confirmed_at = datetime.datetime.now() - datetime.timedelta(days=6000) self.display_name = username @@ -155,6 +155,9 @@ class User(db.Model, UserMixin): self.password = password self.rank = UserRank.NOT_JOINED + def hasPassword(self): + return self.password != "" + def canAccessTodoList(self): return Permission.APPROVE_NEW.check(self) or \ Permission.APPROVE_RELEASE.check(self) or \ @@ -203,6 +206,13 @@ class User(db.Model, UserMixin): return Thread.query.filter_by(author=self) \ .filter(Thread.created_at > hour_ago).count() < 2 + def __eq__(self, other): + if not self.is_authenticated or not other.is_authenticated: + return False + + assert self.id > 0 + return self.id == other.id + class UserEmailVerification(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey("user.id")) |