Commit 1b39d5ecd3d46335fdf5e7b9134ff83469dbe3cc

Authored by Goutte
1 parent 665c1e43
Exists in master

Add a skeleton for the models.

Showing 1 changed file with 43 additions and 0 deletions   Show diff stats
flaskr/models.py 0 → 100755
... ... @@ -0,0 +1,43 @@
  1 +from flask_sqlalchemy import SQLAlchemy
  2 +from flask_login import UserMixin, AnonymousUserMixin
  3 +from werkzeug.security import generate_password_hash, check_password_hash
  4 +
  5 +db = SQLAlchemy()
  6 +
  7 +
  8 +class User(db.Model, UserMixin):
  9 + id = db.Column(db.Integer(), primary_key=True)
  10 + username = db.Column(db.String())
  11 + password = db.Column(db.String())
  12 +
  13 + def __init__(self, username, password):
  14 + self.username = username
  15 + self.set_password(password)
  16 +
  17 + def set_password(self, password):
  18 + self.password = generate_password_hash(password)
  19 +
  20 + def check_password(self, value):
  21 + return check_password_hash(self.password, value)
  22 +
  23 + @property
  24 + def is_authenticated(self):
  25 + if isinstance(self, AnonymousUserMixin):
  26 + return False
  27 + else:
  28 + return True
  29 +
  30 + def is_active(self):
  31 + return True
  32 +
  33 + def is_anonymous(self):
  34 + if isinstance(self, AnonymousUserMixin):
  35 + return True
  36 + else:
  37 + return False
  38 +
  39 + def get_id(self):
  40 + return self.id
  41 +
  42 + def __repr__(self):
  43 + return '<User %r>' % self.username
... ...