# Path: maple/model.py
# class User(db.Model, UserMixin):
#     __tablename__ = 'user'
# 
#     @property
#     def is_admin(self):
#         return self.is_authenticated and self.is_superuser
# 
#     @property
#     def token(self):
#         return self.email_token
# 
#     @classmethod
#     def check_token(cls, token, max_age=24 * 3600 * 30):
#         return cls.check_email_token(token, max_age)
# 
# Path: maple/utils.py
# class MethodView(_MethodView):
#     cache_time = 180
# 
#     def dispatch_request(self, *args, **kwargs):
#         f = super(MethodView, self).dispatch_request
#         if self.cache_time and request.method in ["GET", "HEAD"]:
#             return cache.cached(
#                 timeout=self.cache_time,
#                 key_prefix=cache_key,
#             )(f)(*args, **kwargs)
#         return f(*args, **kwargs)
# 
# def check_params(keys, req=None):
#     '''
#     only check is not NULL
#     '''
#     def _check_params(func):
#         @wraps(func)
#         def decorator(*args, **kwargs):
#             if req is not None:
#                 request_data = req
#             else:
#                 request_data = request.data
#             for key in keys:
#                 if not request_data.get(key):
#                     return HTTP.BAD_REQUEST(message='{0} required'.format(key))
#             return func(*args, **kwargs)
# 
#         return decorator
# 
#     return _check_params


from flask import redirect, request
from flask_babel import gettext as _
from flask_maple.response import HTTP
from maple.model import User
from maple.utils import MethodView, check_params
# ********************************************************************************


class IndexView(MethodView):
    def get(self):
        return HTTP.HTML("index/index.html")


class AboutView(MethodView):
    def get(self):
        return HTTP.HTML("index/about.html")


class FriendView(MethodView):
    def get(self):
        return HTTP.HTML("index/friends.html")


class ContactView(MethodView):
    def get(self):
        return HTTP.HTML("index/contact.html")


class LoginView(MethodView):
    @check_params(['username', 'password'])
    def post(self):
        data = request.data
        username = data['username']
        password = data['password']
        remember = data.pop('remember', True)

# Path: maple/model.py
# class User(db.Model, UserMixin):
#     __tablename__ = 'user'
# 
#     @property
#     def is_admin(self):
#         return self.is_authenticated and self.is_superuser
# 
#     @property
#     def token(self):
#         return self.email_token
# 
#     @classmethod
#     def check_token(cls, token, max_age=24 * 3600 * 30):
#         return cls.check_email_token(token, max_age)
# 
# Path: maple/utils.py
# class MethodView(_MethodView):
#     cache_time = 180
# 
#     def dispatch_request(self, *args, **kwargs):
#         f = super(MethodView, self).dispatch_request
#         if self.cache_time and request.method in ["GET", "HEAD"]:
#             return cache.cached(
#                 timeout=self.cache_time,
#                 key_prefix=cache_key,
#             )(f)(*args, **kwargs)
#         return f(*args, **kwargs)
# 
# def check_params(keys, req=None):
#     '''
#     only check is not NULL
#     '''
#     def _check_params(func):
#         @wraps(func)
#         def decorator(*args, **kwargs):
#             if req is not None:
#                 request_data = req
#             else:
#                 request_data = request.data
#             for key in keys:
#                 if not request_data.get(key):
#                     return HTTP.BAD_REQUEST(message='{0} required'.format(key))
#             return func(*args, **kwargs)
# 
#         return decorator
# 
#     return _check_params


# Path: maple/router.py
from flask import redirect, request
from flask_babel import gettext as _
from flask_maple.response import HTTP
from maple.model import User
from maple.utils import MethodView, check_params

# ********************************************************************************


class IndexView(MethodView):
    def get(self):
        return HTTP.HTML("index/index.html")


class AboutView(MethodView):
    def get(self):
        return HTTP.HTML("index/about.html")


class FriendView(MethodView):
    def get(self):
        return HTTP.HTML("index/friends.html")


class ContactView(MethodView):
    def get(self):
        return HTTP.HTML("index/contact.html")


class LoginView(MethodView):
    @check_params(['username', 'password'])
    def post(self):
        data = request.data
        username = data['username']
        password = data['password']
        remember = data.pop('remember', True)

        user = User.query.filter_by(username=username).first()