示例#1
0
def login():
    username = request.json['username']
    password = request.json['password']

    # get the token back
    query = "SELECT user_id, name FROM `user` WHERE `username` = %s AND `password` = %s"
    arguments = [username, md5_hash(password)]
    result = select_one(query, arguments)
    if result['result'] == 'success':
        token = jwt.encode(result['data'], 'secret', algorithm='HS256')
        data = {'token': token, 'user_id': result['data']['user_id']}
        return jsonify({'result': 'success', 'data': data})
    else:
        return jsonify({'result': 'failure'})
示例#2
0
def get_blog_by_id(blog_id):
    query = 'SELECT * FROM `blog` WHERE `blog_id` = %s'
    result = select_one(query, [blog_id])
    return jsonify(result)