def echo_socket(ws): ws_pool.append(ws) for e in ws_pool: try: e.send("hello") except: ws_pool.remove(e) while not ws.closed: data = json.loads(ws.receive()) phone = data['phone'] message = data['message'] existance = findUser(phone) if existance: revisedMessage = bulletCheck(message) rowcount = addBullet( revisedMessage, phone, ) if (rowcount > 0): for e in ws_pool: e.send(json.dumps({ 'phone': phone, 'data': revisedMessage })) else: ws.send(json.dumps({'errcode': 1, 'errmsg': "请检查网络连接或其他配置"})) else: ws.send(json.dumps({'errcode': 1, 'errmsg': "该手机号未经注册"}))
def login(): if not request.is_json: return jsonify(msg="Missing JSON in request"), 400 username = request.json.get('username', None) password = request.json.get('password', None) if not username or not password: return jsonify(msg="Missing UserName and Password"), 400 all_users = find_all_users() identity_data = { "user_id": "admin_000", "user_name": 'admin', "level": 1 } if len(all_users) <= 0: if username != "admin" or password != "admin": return jsonify(msg="Bad Username and password"), 401 else: match_user = findUser(username, password) if not match_user: return jsonify(msg="Bad Username and password"), 401 identity_data['user_id'] = match_user[0] identity_data['user_name'] = match_user[1] identity_data['level'] = match_user[3] acces_token = create_access_token(identity=identity_data, expires_delta=timedelta(seconds=24 * 3600)) return jsonify(access_token=acces_token), 200
def register(): data = request.get_json() username = data['username'] password = data['password'] result = findUser(username) if result: return {'errcode': 400, 'errmsg': '该用户已被注册'} else: rowcount = createUser(username, password) if rowcount > 0: return {'errcode': 0, 'errmsg': '注册成功'} else: return {'errcode': 1, 'errmsg': '注册失败'}
def register(): data = request.get_json() username = data['username'] password = data['password'] result = findUser(username) if result: return {'errcode': 400, 'errmsg': '该用户名已被注册'}, 400 rowcount = createUser(username, password) if rowcount > 0: return {'errcode': 0, 'errmsg': '注册成功'}, 200 return {'errcode': 400, 'errmsg': '请检查网络或其他设置'}, 400
def post(self,*args,**kwargs): if self.request.headers['Content-Type'] == 'application/json': data=json.loads(self.request.body) phone=data['phone'] password=data['password'] nickname=data['nick_name'] result=findUser(phone) if result: msg={'errcode':1,'errmsg':'手机号已被注册!'} elif(result==checkPhone(phone)): msg={'errcode':1,'errmsg':'请输入正确的手机号!'} else: result=createUser(phone,password,nickname) if result: msg={'errcode':0,'errmsg':'注册成功!'} self.write(json.dumps(msg))
def register():#用户注册 #获取前端数据 data = request.get_json() username = data['username'] password = data['password'] result = findUser(username) if result: return{ 'errcode':400, 'errmsg': '该用户已被注册' },400 rowcount = createUser(username, password) if rowcount > 0: return { 'errcode': 0, 'errmsg': '注册成功' }, 200 return { 'errcode': 400, 'errmsg': '出现错误,请重试' },400
def register(): data=request.get_json() if findUser(data['username']): return{'errcode':400,'errmsg':'您已经注册'},400 if(subtimein(data)>0): return{"errcode":200,"errmag":"注册成功"}