def getdl2(): str = request.get_json() print(str) print(str['username']) str2 = request.get_data() print(str2) return jsonify(trueReturn("{'ok':True}", API_SUCCESS_MSG))
def identify(self, request): """ 用户鉴权 :return: list """ auth_header = request.headers.get('Authorization') if (auth_header): auth_tokenArr = auth_header.split(" ") if (not auth_tokenArr or auth_tokenArr[0] != 'JWT' or len(auth_tokenArr) != 3): result = falseReturn('', '请传递正确的验证头信息') else: auth_token = auth_tokenArr[2] payload = self.decode_auth_token(auth_token) if not isinstance(payload, str): user = User.get(User, payload['data']['id']) if (user is None): result = falseReturn('', '找不到该用户信息') else: if (user.login_time == payload['data']['login_time']): result = trueReturn(user.id, '请求成功') else: result = falseReturn('', 'Token已更改,请重新登录获取') else: result = falseReturn('', payload) else: result = falseReturn('', '没有提供认证token') return result
def register(): """ 用户注册 :return: json """ email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') # 最后一条记录及其ID lastUserRecord = User.query.order_by(desc('id')).first() if (lastUserRecord is None): newRecordId = 1 else: newRecordId = lastUserRecord.id + 1 user = User(id=newRecordId, email=email, username=username, password=User.set_password(User, password)) User.add(User, user) userInfo = User.get(User, user.id) if userInfo: returnUser = { 'id': userInfo.id, 'username': userInfo.username, 'email': userInfo.email, 'login_time': userInfo.login_time } return jsonify(trueReturn(returnUser, REGISTER_SUCCESS_MSG)) else: return jsonify(falseReturn('', REGISTER_FAILURE_MSG))
def get_product_by_barcode(branchcode, barcode): productbarcode = ProductBarCode(branchcode) rst = productbarcode.seek_branch_product_barcode(barcode) # barcode查询步到,使用prodid查询 if len(rst) == 2: rst = productbarcode.seek_branch_product_proid(barcode) return jsonify(trueReturn(rst, API_SUCCESS_MSG))
def login(): name = request.form.get('username') password = request.form.get('password') admin = User.query.filter_by(username=name).first() if admin == None: return jsonify(trueReturn("{'ok':Flase}", API_FAILURE_MSG)) else: return Auth.authenticate(Auth, name, password)
def authenticate(self, username, password): """ 用户登录,登录成功返回token,写将登录时间写入数据库;登录失败返回失败原因 :param password: :return: json """ userInfo = User.query.filter_by(username=username).first() if (userInfo is None): return jsonify(falseReturn('', '找不到用户')) else: if (User.check_password(User, userInfo.password, password)): login_time = int(time.time()) userInfo.login_time = login_time User.update(User) token = self.encode_auth_token(userInfo.id, login_time) return jsonify(trueReturn(token.decode(), '登录成功')) else: return jsonify(falseReturn('', '密码不正确'))
def getuserinfo(id): lds = User.query.filter_by(id=id).first() return jsonify( trueReturn(json.dumps(lds.columns_to_dict()), API_SUCCESS_MSG))
def getUser2(): user = utils._get_user() return jsonify(trueReturn(user.columns_to_dict(), API_SUCCESS_MSG))
def get_branch_result(): branchcode = '01001' branch = Branch(branchcode) rst = branch.get_branch_all() return jsonify(trueReturn(rst, API_SUCCESS_MSG))
def logout(): logout_user() return jsonify(trueReturn("{'ok':True}", API_SUCCESS_MSG))
def Get_memeber_by_mobile(mobile): member = Member() rst = member.seek_memeber_by_mobile(mobile) return jsonify(trueReturn(rst, API_SUCCESS_MSG))