示例#1
0
    def post(self):
        auth_header = request.headers.get('Authorization')
        if auth_header:
            access_token = auth_header.split(" ")[1]
        else:
            return {
                "message": "This method requires an authorization header."
            }, 400
        error, client_id = auth_by_token(access_token)
        if error:
            return {"message": error}, 401

        if UserController.not_admin(client_id):
            return {
                "message":
                "Only the priveleged can come here. Get out peasant."
            }, 400

        data = ThemeAdmin.parser.parse_args()
        error_message = ThemeController.create_theme(data["release_time"],
                                                     data["theme"],
                                                     data["theme_inspire"],
                                                     data["theme_author"])
        if error_message:
            return {"message": error_message}, 400
        else:
            return {"message": "Success!"}, 201
示例#2
0
    def put(self):
        if UserController.not_admin():
            return {
                "message":
                "Only the priveleged can come here. Get out peasant."
            }, 400

        data = ThemeAdmin.parser.parse_args()
        error_message = ThemeController.update_theme(data["release_time"],
                                                     data["theme"],
                                                     data["theme_inspire"],
                                                     data["theme_author"])
        if error_message:
            return {"message": error_message}, 400
        else:
            return {"message": "Success!"}
示例#3
0
    def get(self, year, month, day):
        if UserController.not_admin(current_identity):
            return {
                "message":
                "Only the priveleged can come here. Get out peasant."
            }, 400

        if safe_str_cmp(day, "all"):
            error_message, response = ThemeController.get_for_month(
                year, month)
        elif day.isdigit():
            error_message, response = ThemeController.get_for_day(
                year, month, int(day))
        else:
            return {"message": "Unsupported mode of get"}, 400

        if error_message:
            return {"message": error_message}, 500
        else:
            return {
                "response": list(map(lambda x: x.json()
                                     if x else "", response))
            }
示例#4
0
    def get(self, year, month, day):
        auth_header = request.headers.get('Authorization')
        if auth_header:
            access_token = auth_header.split(" ")[1]
        else:
            return {"message": "This method requires an authorization header."}, 400
        error, client_id = auth_by_token(access_token)
        if error:
            return {"message": error}, 401

        if UserController.not_admin(client_id):
            return {"message": "Only the priveleged can come here. Get out peasant."}, 401

        if safe_str_cmp(day, "all"):
            error_message, response = ThemeController.get_for_month(year, month)
        elif day.isdigit():
            error_message, response = ThemeController.get_for_day(year, month, int(day))
        else:
            return {"message": "Unsupported mode of get"}, 400

        if error_message:
            return {"message": error_message}, 500
        else:
            return {"response": list(map(lambda x: x.json() if x else "", response))}