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
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')
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)
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
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
def agoods(page): if request.method == 'POST': try: token = request.cookies.get('token') if not myModule.deJWT(token): return '请重新登录', 400 keyword = request.get_data().decode('utf-8') goods = myModule.searchGoods(keyword, page) msg = {'amount': len(goods), 'list': goods} return jsonify(msg) except: return 'Bad Request', 400 return 'Bad Request', 400
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")
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)
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
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
def test_chat(): token = request.cookies.get('token') if not myModule.deJWT(token): return '请重新登录', 400 return str(user_list)