Esempio n. 1
0
    def get(self, mode, days):
        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 safe_str_cmp(mode, "now"):
            error_message, response = ThemeController.get_now()
        elif safe_str_cmp(mode, "browse"):
            error_message, response = ThemeController.browse(int(days), client_id)
        else:
            return {"message": "Unsupported mode."}, 400

        if safe_str_cmp(mode, "browse"):
            return {"response": response}

        if error_message:
            return {"message": error_message}, 500


        return {"response": list(map(lambda x: x.json() if x else None, response))}
Esempio n. 2
0
 def get(self, mode, index):
     if safe_str_cmp(mode, "now"):
         error_message, response = ThemeController.get_now()
     if safe_str_cmp(mode, "browse"):
         error_message, response = ThemeController.browse(index)
     else:
         return {"message": "Unsupported mode."}, 400
     if error_message:
         return {"message": error_message}, 500
     return {
         "response": list(map(lambda x: x.json() if x else None, response))
     }
Esempio n. 3
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
Esempio n. 4
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))
            }
Esempio n. 5
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))}
Esempio n. 6
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!"}