def verify_auth_token(token): s = Serializer(app.secret_key) try: data = s.loads(token) except SignatureExpired: return None except BadSignature: return None db_session = Session() user = db_session.query(User).filter(User.id == data['id']) db_session.close() return user
def verify_password(useremail_or_token, password): # first try to authenticate by token db_session = Session() user = User.verify_auth_token(useremail_or_token) if not user: # try to authenticate with email/password user = db_session.query(User).filter_by( email=useremail_or_token).first() if not user or not user.verify_password(password): return False g.user = user db_session.close() return True
def get_collections(): data_type = request.get_json().get('data_type') items = [] session = Session() if data_type == 'HOME_LIST': items = get_homelist(session, request) elif data_type == 'HOT_RANK': items = get_ranklist(session, request) elif data_type == 'HOT_RECOMMEND': items = get_recommendlist(session, request) elif data_type == 'PACK_LIST': items = get_packlist(session, request) result = json.dumps({ "state": OPER_SUCCESS, "result": items }, ensure_ascii=False, cls=AlchemyEncoder) session.close() return result, 200, { 'Cache-Control': 'max-age=50' }