# Path: handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, application, request, **kwargs):
#         super(BaseHandler, self).__init__(application, request, **kwargs)
#         self.session = DB_Session()
# 
#     def data_received(self, chunk):
#         pass
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("username")
# 
#     def on_finish(self):
#         self.session.close()
# 
# Path: models/models.py
# class User(BaseModel):
#     __tablename__ = 'user'
# 
#     id = Column(Integer, Sequence('user_id_seq'), primary_key=True)  # id
#     username = Column(String(32))  # 用户名
#     password = Column(CHAR(64))  # 密码
#     email = Column(String(32))  # 邮箱
#     is_active = Column(BOOLEAN)  # 是否激活
#     is_admin = Column(BOOLEAN)  # 是否管理员
#     data = Column(DATE)  # 新建时间
#     tell_phone = Column(CHAR(11))  # 电话号码
#     my_task = relationship("MyTask", backref="user")  # 对应的任务
#     company_id = Column(Integer, ForeignKey('company.id'))  # 外键  公司
#     userGroup = relationship('UserGroup', secondary=user_userGroup, back_populates='user')


import hashlib
import tornado
import tornado.gen
import logging
import time
from sqlalchemy import and_
from handlers.base import BaseHandler
from models.models import User
#!/usr/bin/env python
# _*_coding:utf-8_*_


class LoginHandler(BaseHandler):
    def get(self):
        self.render('sys_login.html', login_err='')

    def post(self):
        username = self.get_argument('username')
        password = hashlib.sha256(self.get_argument('password').encode('utf-8')).hexdigest()

# Path: handlers/base.py
# class BaseHandler(tornado.web.RequestHandler):
#     def __init__(self, application, request, **kwargs):
#         super(BaseHandler, self).__init__(application, request, **kwargs)
#         self.session = DB_Session()
# 
#     def data_received(self, chunk):
#         pass
# 
#     def get_current_user(self):
#         return self.get_secure_cookie("username")
# 
#     def on_finish(self):
#         self.session.close()
# 
# Path: models/models.py
# class User(BaseModel):
#     __tablename__ = 'user'
# 
#     id = Column(Integer, Sequence('user_id_seq'), primary_key=True)  # id
#     username = Column(String(32))  # 用户名
#     password = Column(CHAR(64))  # 密码
#     email = Column(String(32))  # 邮箱
#     is_active = Column(BOOLEAN)  # 是否激活
#     is_admin = Column(BOOLEAN)  # 是否管理员
#     data = Column(DATE)  # 新建时间
#     tell_phone = Column(CHAR(11))  # 电话号码
#     my_task = relationship("MyTask", backref="user")  # 对应的任务
#     company_id = Column(Integer, ForeignKey('company.id'))  # 外键  公司
#     userGroup = relationship('UserGroup', secondary=user_userGroup, back_populates='user')


# Path: handlers/login.py
import hashlib
import tornado
import tornado.gen
import logging
import time
from sqlalchemy import and_
from handlers.base import BaseHandler
from models.models import User

#!/usr/bin/env python
# _*_coding:utf-8_*_


class LoginHandler(BaseHandler):
    def get(self):
        self.render('sys_login.html', login_err='')

    def post(self):
        username = self.get_argument('username')
        password = hashlib.sha256(self.get_argument('password').encode('utf-8')).hexdigest()

        user = self.session.query(User).filter(and_(User.username == username, User.password == password)).first()