def get(self, id): self.country_type = mongo.db.countryType.find({ '_id': ObjectId(id) }) if not self.country_type: return {'message': "CountryType with ID {} does not exist".format(id)}, 404, headers return bsonToJson(self.country_type), 200
def get(self, id): unit_type = mongo.db.unitType.find({'_id': ObjectId(id)}) if not unit_type: return { 'message': "UnitType with ID {} does not exist".format(id) }, 404, headers return bsonToJson(unit_type), 200
def get(self, id): terrain_type = mongo.db.terrainType.find({'_id': ObjectId(id)}) if not terrain_type: return { 'message': "TerrainType with ID {} does not exist".format(id) }, 404, headers return bsonToJson(terrain_type), 200,
def get(self, id): try: self.user = mongo.db.users.find_one({'_id': ObjectId(id)}, {'password': False}) if not self.user: return { 'message': "User with ID {} does not exist".format(id) }, 404, headers except InvalidId: return {'message': "Invalid ID {}".format(id)}, 400, headers return bsonToJson(self.user), 200
def put(self, id): args = self.reqparse.parse_args() try: self.user = mongo.db.users.find_one({'_id': ObjectId(id)}, {'password': False}) if not self.user: return { 'message': "User with ID {} does not exist".format(id) }, 404, headers except InvalidId: return {'message': "Invalid ID {}".format(id)}, 400, headers # mongo.db.users.update({ '_id': ObjectId(id)}, { $set: { 'password': hash_password(args['password'])} }) return bsonToJson(self.user), 200
def post(self): args = self.reqparse.parse_args() if args['Awbw-Token']: token_data = verify_auth_token(args['Awbw-Token']) if not token_data: return {"message": "Invalid user token"}, 401, headers user = { '_id': token_data["_id"], 'username': token_data["username"] } message = "Logged in with token" else: user = mongo.db.users.find_one({'username': args['username']}) if not user: return { "message": "Login with username {} does not exist".format( args['username']) }, 404, headers if not verify_password(args['password'], user['password']): return { "message": "Invalid password for user {}".format(args['username']) }, 401, headers message = "Logged in with credentials" return { "message": message, "username": user["username"], "token": generate_auth_token(bsonToJson(user)) }, 200
def get(self): return bsonToJson(list(mongo.db.countryType.find())), 200
def get(self): return bsonToJson(list(mongo.db.terrainType.find())), 200
def get(self): return bsonToJson(list(mongo.db.unitType.find())), 200