# Path: webtools/auth/models.py
# class User(Base):
#     __tablename__ = 'users'
# 
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     username = Column(Unicode(200), nullable=False, index=True)
#     first_name = Column(Unicode(200), nullable=False)
#     last_name = Column(Unicode(200), nullable=False)
#     email = Column(Unicode(200), nullable=False)
#     password = Column(String(200), nullable=False)
# 
#     def __repr__(self):
#         return "<User {0}>".format(self.id)
# 
#     def set_password(self, password):
#         self.password = make_password(password)
# 
#     def check_password(self, password):
#         return check_password(password, self.password)


from .models import User
# -*- coding: utf-8 -*-



class AuthHandlerMixin(object):
    def authenticate(self, username, password):
        user = self.application.authenticate(username=username, password=password)
        if user is not None:
            self.session["user_id"] = user.id

    def get_current_user(self):
        if hasattr(self, "_user"):
            return self._user

        if "user_id" in self.session:

# Path: webtools/auth/models.py
# class User(Base):
#     __tablename__ = 'users'
# 
#     id = Column(Integer, primary_key=True, autoincrement=True)
#     username = Column(Unicode(200), nullable=False, index=True)
#     first_name = Column(Unicode(200), nullable=False)
#     last_name = Column(Unicode(200), nullable=False)
#     email = Column(Unicode(200), nullable=False)
#     password = Column(String(200), nullable=False)
# 
#     def __repr__(self):
#         return "<User {0}>".format(self.id)
# 
#     def set_password(self, password):
#         self.password = make_password(password)
# 
#     def check_password(self, password):
#         return check_password(password, self.password)


# Path: webtools/auth/handlers.py
from .models import User

# -*- coding: utf-8 -*-



class AuthHandlerMixin(object):
    def authenticate(self, username, password):
        user = self.application.authenticate(username=username, password=password)
        if user is not None:
            self.session["user_id"] = user.id

    def get_current_user(self):
        if hasattr(self, "_user"):
            return self._user

        if "user_id" in self.session:

            self._user = self.db.query(User).filter(User.id == self.session["user_id"]).one()