# 关联关系的接口开发
# 1、写一个登录后把session写到redis里面,返回sessionId
# 2、获得session后 可以返回生成双色球的信息
# 分析:1、先验证是否登录,如已经登录,获取username 和 session
# 2、验证session是否正确,判断用户传过来的session和redis里是否一致
# 1、session正确,返回信息
# 2、session不一致,提示非法,如果不存在的话,提示用户未登录
# import flask
# def login():
# username = flask.request.values.get('username','')
# password = flask.request.values.get('password','')
# sql = "select * from user WHERE username=%s AND password = %s;"
# res =op_mysql(sql,[username,password])
#
# if res:
# k = "session:%s"%username
# v = str(time.time())+username #session 策略是 当前时间戳加username然后md5
# session = md5_password(v)
# op_redis(k,session,expired=30,db=2)
# response = {'code': '309', 'msg': '登录成功','session':session}
# else:
# response = {'code': '308', 'msg': '账号/密码错误'}
# return json.dumps(response, ensure_ascii=False)