From 1b39d5ecd3d46335fdf5e7b9134ff83469dbe3cc Mon Sep 17 00:00:00 2001 From: Goutte Date: Wed, 16 Oct 2019 16:08:36 +0200 Subject: [PATCH] Add a skeleton for the models. --- flaskr/models.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+), 0 deletions(-) create mode 100755 flaskr/models.py diff --git a/flaskr/models.py b/flaskr/models.py new file mode 100755 index 0000000..56510bc --- /dev/null +++ b/flaskr/models.py @@ -0,0 +1,43 @@ +from flask_sqlalchemy import SQLAlchemy +from flask_login import UserMixin, AnonymousUserMixin +from werkzeug.security import generate_password_hash, check_password_hash + +db = SQLAlchemy() + + +class User(db.Model, UserMixin): + id = db.Column(db.Integer(), primary_key=True) + username = db.Column(db.String()) + password = db.Column(db.String()) + + def __init__(self, username, password): + self.username = username + self.set_password(password) + + def set_password(self, password): + self.password = generate_password_hash(password) + + def check_password(self, value): + return check_password_hash(self.password, value) + + @property + def is_authenticated(self): + if isinstance(self, AnonymousUserMixin): + return False + else: + return True + + def is_active(self): + return True + + def is_anonymous(self): + if isinstance(self, AnonymousUserMixin): + return True + else: + return False + + def get_id(self): + return self.id + + def __repr__(self): + return '' % self.username -- libgit2 0.21.2