Skip to content

Instantly share code, notes, and snippets.

@altendky
Forked from RyanBreaker/models.py
Last active December 22, 2017 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save altendky/cfd9d3086eea753d12bed2a2c83bede7 to your computer and use it in GitHub Desktop.
Save altendky/cfd9d3086eea753d12bed2a2c83bede7 to your computer and use it in GitHub Desktop.
class IdModel:
id = db.Column(db.Integer, primary_key=True)
class User(IdModel, UserMixin, db.Model):
username = db.Column(db.String(64), index=True, unique=True)
email = db.Column(db.String(128), index=True, unique=True)
password_hash = db.Column(db.String(128))
def __repr__(self):
return '<User {}>'.format(self.username)
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password_hash, password)
@classmethod
@login.user_loader
def load_user(cls, id_):
return cls.query.get(int(id_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment