def get(self): query = dict(mch_id=get_current_user().mch_id) pager = page_param() data = MONGODB.get_db(self.col_name).find(query, skip=pager.skip, limit=pager.limit) assert data return jsonify(DataSchema(many=True).load(data, unknown=INCLUDE))
def put(self): query = dict(_id=get_current_user().get_id()) data = request.get_json() assert data info = DataSchema(exclude=('_id', ), partial=True).load(data, unknown=INCLUDE) return dict(result=str( MONGODB.get_db(self.col_name).update_one(query, { '$set': info }).acknowledged))
def post(self): pwd = ChangePasswordParam.get_param() user_id = get_current_user().get_id() user = MONGODB.get_db(self.col_name).find_one({'_id': user_id}, {'password': 1}) if not user: raise HandlerException(status_code=500, message='unknown error') if not check_password_hash(user['password'], pwd.get('old_password')): raise HandlerException(status_code=403, message='error old password') result = MONGODB.get_db(self.col_name).update_one({'_id': user_id}, { '$set': { 'password': generate_password_hash(pwd['new_password']) } }) if result.modified_count != 1: raise HandlerException(status_code=403, message='change password failed') return 'ok'
def get(self): query = dict(_id=get_current_user().get_id()) data = MONGODB.get_db(self.col_name).find_one(query) assert data return DataSchema().load(data, unknown=INCLUDE)
def get(self): query = dict(_id=get_current_user().mch_id) data = MONGODB.get_db(self.col_name).find_one(query) if data is not None: data = DataSchema().load(data, unknown=INCLUDE) return jsonify(data)
def get(self, _id): query = dict(_id=_id, mch_id=get_current_user().mch_id) data = MONGODB.get_db(self.col_name).find_one(query) assert data, 'not found' return DataSchema().load(data, unknown=INCLUDE)