37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Module containing user related models."""
|
|
|
|
# vim: set tw=80 ts=4 sw=4 sts=4:
|
|
|
|
from passlib.hash import sha256_crypt as crypt
|
|
|
|
from . import db
|
|
|
|
|
|
# pylint: disable=no-member,invalid-name
|
|
# pylint: disable=too-few-public-methods,too-many-instance-attributes
|
|
class User(db.Model):
|
|
"""Class used to handle users."""
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
email = db.Column(db.String(200), nullable=False, unique=True, index=True)
|
|
password = db.Column(db.String(100), nullable=True)
|
|
active = db.Column(db.Boolean, nullable=False, default=True,
|
|
server_default=db.true())
|
|
|
|
def is_active(self):
|
|
"""Return True if user is active."""
|
|
return self.active
|
|
|
|
@classmethod
|
|
def query(cls):
|
|
"""Return a query for this class."""
|
|
return db.session.query(cls)
|
|
|
|
@classmethod
|
|
def hash_password(cls, password):
|
|
"""Password hash function."""
|
|
return crypt.encrypt(password)
|
|
|
|
def verify_password(self, password):
|
|
"""Verify password passed in argument with the user's one."""
|
|
return crypt.verify(password, self.password)
|