# Path: mod/models/library_auth_cache.py
# class LibraryAuthCache(Base):
#     __tablename__ = 'library_auth'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(4096))
#     captcha = Column(String(4096))
#     date = Column(Integer, nullable=False)


from config import *
from tornado.httpclient import HTTPClient
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from bs4 import BeautifulSoup
from ..models.library_auth_cache import LibraryAuthCache
from sqlalchemy.orm.exc import NoResultFound
from time import time
import re
import json
import urllib
import base64
import tornado.web, tornado.gen
                    'passwd': password,
                    'captcha': captcha,
                    'select': 'cert_no'
                }
                request = HTTPRequest(
                    LOGIN_URL,
                    method='POST',
                    headers={'Cookie': cookies},
                    body=urllib.urlencode(form_data),
                    request_timeout=TIME_OUT
                    )
                response = yield tornado.gen.Task(client.fetch, request)
                soup = BeautifulSoup(response.body, 'html.parser')
                name = soup.findAll('font')[0].text
                if name:
                    retjson['code'] = 200
                    retjson['content'] = 'auth success'
                else:
                    retjson['code'] = 401
                    retjson['content'] = 'auth error'
            except Exception as e:
                retjson['code'] = 500
                retjson['content'] = 'error'
        ret = json.dumps(retjson, ensure_ascii=False, indent=2)
        self.write(ret)
        self.finish()

        # refresh cache
        if (retjson['code'] == 200):
            status.password = password

# Path: mod/models/library_auth_cache.py
# class LibraryAuthCache(Base):
#     __tablename__ = 'library_auth'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(4096))
#     captcha = Column(String(4096))
#     date = Column(Integer, nullable=False)


# Path: mod/library/listhandler.py
from config import *
from tornado.httpclient import HTTPClient
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from bs4 import BeautifulSoup
from ..models.library_auth_cache import LibraryAuthCache
from sqlalchemy.orm.exc import NoResultFound
from time import time
import re
import json
import urllib
import base64
import tornado.web, tornado.gen

                    'passwd': password,
                    'captcha': captcha,
                    'select': 'cert_no'
                }
                request = HTTPRequest(
                    LOGIN_URL,
                    method='POST',
                    headers={'Cookie': cookies},
                    body=urllib.urlencode(form_data),
                    request_timeout=TIME_OUT
                    )
                response = yield tornado.gen.Task(client.fetch, request)
                soup = BeautifulSoup(response.body, 'html.parser')
                name = soup.findAll('font')[0].text
                if name:
                    retjson['code'] = 200
                    retjson['content'] = 'auth success'
                else:
                    retjson['code'] = 401
                    retjson['content'] = 'auth error'
            except Exception as e:
                retjson['code'] = 500
                retjson['content'] = 'error'
        ret = json.dumps(retjson, ensure_ascii=False, indent=2)
        self.write(ret)
        self.finish()

        # refresh cache
        if (retjson['code'] == 200):
            status.password = password

            status.captcha = captcha