예제 #1
0
def handleChecks():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        return '请重新登录', 400
    user = myModule.getUserFromJWT(token)
    if user['privilege'] != 0:
        return '请重新登录', 400

    if request.method == 'GET':
        try:
            goods = myModule.getCheck(user)
            return jsonify({'number': len(goods), 'list': goods}), 200
        except:
            return 'Bad Request', 400

    if request.method == 'PUT':
        try:
            msg = request.get_data().decode('utf-8')
            myModule.rejectCheck(msg)
            return 'OK', 200
        except:
            return 'Bad Request', 400

    if request.method == 'POST':
        try:
            msg = request.get_data().decode('utf-8')
            myModule.passCheck(msg)
            return 'OK', 200
        except:
            return 'Bad Request', 400
예제 #2
0
def signToDb():
    if request.method == 'POST':
        msg = json.loads(request.get_data().decode('utf-8'))
        if msg['privilege'] == 0:
            return 'Bad Request', 400
        flag = myModule.anaSign(msg)
        if flag == 0:
            token = request.cookies.get('token')
            if type(token) == str:
                user = myModule.getUserFromJWT(token)
                if user['privilege'] == 0:
                    myModule.addUser(msg)
                    return 'OK', 200
            myModule.addUser(msg)
            JWT = myModule.encodeJWT(msg)
            if msg['privilege'] == 1:
                resp = make_response(redirect(url_for('welCustomer')))
            elif msg['privilege'] == 2:
                resp = make_response(redirect(url_for('welSeller')))
            resp.set_cookie("token", JWT, httponly=True, max_age=86400)
            return resp
        elif flag == 1:
            return '用户名已存在', 400
        elif flag == 2:
            return '邮箱已被注册', 400
        else:
            return 'Bad Request', 400
예제 #3
0
def welCustomer():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        return redirect("/")
    user = myModule.getUserFromJWT(token)
    if user['privilege'] != 1:
        return '请重新登录', 400
    return send_file('./html/Mall.html')
예제 #4
0
def test_connect():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        emit('error', '请重新登录')
    else:
        user = myModule.getUserFromJWT(token)
        user_chat[user['user']] = request.sid
        user_list.append(user['user'])
        records = myModule.getRecord(user)
        emit('my response', records)
예제 #5
0
def findRecord():
    if request.method == 'POST':
        token = request.cookies.get('token')
        if not myModule.deJWT(token):
            return '请重新登录', 400
        user = myModule.getUserFromJWT(token)
        target = request.get_data().decode('utf-8')
        record = myModule.findRecord(user['user'], target)
        return jsonify({'msg': json.loads(record)}), 200
    return 'Bad Request', 400
예제 #6
0
def orders():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        return '请重新登录', 400
    user = myModule.getUserFromJWT(token)
    if user['privilege'] != 2:
        return '请重新登录', 400

    orders = myModule.getOrders(user)
    return jsonify({'amount': len(orders), 'list': orders}), 200
예제 #7
0
def welcome():
    token = request.cookies.get('token')
    if myModule.deJWT(token):
        user = myModule.getUserFromJWT(token)
        if user['privilege'] == 0:
            resp = make_response(redirect(url_for('welAdmin')))
        elif user['privilege'] == 1:
            resp = make_response(redirect(url_for('welCustomer')))
        elif user['privilege'] == 2:
            resp = make_response(redirect(url_for('welSeller')))
        else:
            return 'Bad Request', 400
        return resp
    return send_file("./html/index.html")
예제 #8
0
def sent_msg(data):
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        emit('error', '请重新登录', room=request.sid)
        return 0
    else:
        get = 0
        user = myModule.getUserFromJWT(token)
        data['from'] = user['user']
        target = user_chat.get(data['to'])
        if target != None:
            get = 1
            myModule.insertRecord(data, get)
            data.pop('_id')
            emit('recvMsg',
                 json.dumps(data, default=json_util.default),
                 room=target)
        else:
            myModule.insertRecord(data, get)
            data.pop('_id')
        return json.dumps(data, default=json_util.default)
예제 #9
0
def goods():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        return '请重新登录', 400
    user = myModule.getUserFromJWT(token)
    if user['privilege'] != 2:
        return '请重新登录', 400
    # 获取商品信息
    if request.method == 'GET':
        good1 = myModule.getGoods(user)
        good2 = myModule.getCheck(user)
        return jsonify({'on': good1, 'check': good2}),200
    # 上架商品(送去审核)
    if request.method == 'POST':
        try:
            msg = json.loads(request.get_data().decode('utf-8'))
            myModule.setCheck(user, msg)
            return 'OK', 200
        except:
            return 'Bad Request', 400
    # 下架商品
    if request.method == 'DELETE':
        try:
            msg = json.loads(request.get_data().decode('utf-8'))
            status=myModule.deleteGoods(user,msg)
            if status==400:
                return 'Bad Request',400
            return 'OK', 200
        except:
            return 'Bad Request', 400
    # 修改商品信息(先下架后审核再上架)
    if request.method == 'PUT':
        try:
            msg = json.loads(request.get_data().decode('utf-8'))
            myModule.updateGoods(user, msg)
            return 'OK', 200
        except:
            return 'Bad Request', 400
예제 #10
0
def handleUser():
    token = request.cookies.get('token')
    if not myModule.deJWT(token):
        return '请重新登录', 400
    user = myModule.getUserFromJWT(token)
    if user['privilege'] != 0:
        return '请重新登录', 400
    if request.method == 'GET':
        try:
            users = myModule.getUser()
            return jsonify(users), 200
        except:
            return 'Bad Request', 400

    if request.method == 'POST':
        try:
            msg = json.loads(request.get_data().decode('utf-8'))
            flag = myModule.anaSign(msg)
            if flag == 0:
                myModule.addUser(msg)
                return 'OK', 200
            elif flag == 1:
                return '用户名已存在', 400
            elif flag == 2:
                return '邮箱已被注册', 400
            else:
                return 'Bad Request', 400
        except:
            return 'Bad Request', 400

    if request.method == 'DELETE':
        try:
            msg = request.get_data().decode('utf-8')
            myModule.deleteUser(msg)
            return 'OK', 200
        except:
            return 'Bad Request', 400
예제 #11
0
def test_disconnect():
    token = request.cookies.get('token')
    user = myModule.getUserFromJWT(token)
    user_chat.pop(user['user'])
    user_list.remove(user['user'])