# Path: mod/models/cookie_cache.py
# class CookieCache(Base):
#     __tablename__ = 'cookie'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(256), nullable=False)
#     date = Column(Integer, nullable=False)


import time,json
import urllib
from tornado.httpclient import HTTPRequest, HTTPClient,HTTPError
from ..models.cookie_cache import CookieCache
from sqlalchemy.orm.exc import NoResultFound
from config import *
from newHandler import newAuthApi
from handler import authApi
# -*- coding: utf-8 -*-
# @Date    : 2016-03-24 16 16:34:57
# @Author  : jerry.liangj@qq.com


def getCookie(db,cardnum,card_pwd):
	state = 1
	ret = {'code':200,'content':''}
	try:
		result = db.query(CookieCache).filter(CookieCache.cardnum==cardnum).one()
		if (result.date+COOKIE_TIMEOUT<int(time.time())):
			state = 0
		else:
			ret['content'] = result.cookie
	except NoResultFound:

# Path: mod/models/cookie_cache.py
# class CookieCache(Base):
#     __tablename__ = 'cookie'
#     cardnum = Column(Integer, primary_key=True)
#     cookie = Column(String(256), nullable=False)
#     date = Column(Integer, nullable=False)


# Path: mod/auth/cookie.py
import time,json
import urllib
from tornado.httpclient import HTTPRequest, HTTPClient,HTTPError
from ..models.cookie_cache import CookieCache
from sqlalchemy.orm.exc import NoResultFound
from config import *
from newHandler import newAuthApi
from handler import authApi

# -*- coding: utf-8 -*-
# @Date    : 2016-03-24 16 16:34:57
# @Author  : jerry.liangj@qq.com


def getCookie(db,cardnum,card_pwd):
	state = 1
	ret = {'code':200,'content':''}
	try:
		result = db.query(CookieCache).filter(CookieCache.cardnum==cardnum).one()
		if (result.date+COOKIE_TIMEOUT<int(time.time())):
			state = 0
		else:
			ret['content'] = result.cookie
	except NoResultFound:

		result = CookieCache(cardnum=cardnum,cookie="",date=int(time.time()))