Пример #1
0
    def post(cls):
        # if get_jwt_claims()["type"] != "admin":
        #    return {"message": "Admin authorization required."}, 401
        _admin_parser_ = reqparse.RequestParser()
        _admin_parser_.add_argument("username",
                                    type=str,
                                    required=True,
                                    help=BLANK)
        _admin_parser_.add_argument("password",
                                    type=str,
                                    required=True,
                                    help=BLANK)
        _admin_parser_.add_argument("first_name",
                                    type=str,
                                    required=True,
                                    help=BLANK)
        _admin_parser_.add_argument("last_name",
                                    type=str,
                                    required=True,
                                    help=BLANK)
        data = _admin_parser_.parse_args()
        if (data["username"].isspace() or data["password"].isspace()
                or data["first_name"].isspace()
                or data["last_name"].isspace()):
            return {"message": "One of the inputs is empty"}, 400

        if len(data["username"]) < 5:
            return {"message": "Username is too short"}, 400

        if AdminModel.find_by_username(data["username"]):
            return {"message": "This admin already exists"}

        admin = AdminModel(**data)
        admin.save_to_db()
        return {"message": "Admin created successfully."}
def populate_admin_table():
    for row in admin_codes:
        new_admin_model = AdminModel(*row)
        if AdminModel.find_by_code_and_country(new_admin_model.admin_code,
                                               new_admin_model.country_code):
            continue
        new_admin_model.save_to_db()
Пример #3
0
    def post(self):
        data = AdminRegister.parser.parse_args()

        if AdminModel.find_by_email(data['email']):
            return {"message": "User already registered"}, 400

        admin = AdminModel(**data)
        admin.save_to_db()

        return {"message": "User created successfully"}, 201
Пример #4
0
    def post(self):
        data = AdminRegister.parser.parse_args()

        if AdminModel.find_by_adminname(data['adminname']):
            return {"message": "An admin with that adminname already exists"}, 400

        admin = AdminModel(**data)
        admin.save_to_db()

        return {"message": "Admin created successfully."}, 201
Пример #5
0
    def put(self, admin_code, country_code):
        data = Admin.parser.parse_args()

        entry = AdminModel.find_by_code_and_country(admin_code, country_code)

        if entry:
            entry.description = data['description']
        else:
            entry = AdminModel(admin_code, country_code, data['description'])
        try:
            entry.save_to_db()
        except:
            {'message': 'Something went wrong inserting the admin.'}, 500
        return entry.json(), 201
Пример #6
0
    def post(self):
        data = AdminRegister.registerparser.parse_args()

        if AdminModel.find_by_username(data['username']):
            return {
                "message": "An admin with that username already exists"
            }, 409

        admin = AdminModel(**data)
        try:
            admin.save_to_db()
        except:
            return {"message": "An error occured registering admin"}, 500

        return {"message": "Admin created successfully"}, 201
Пример #7
0
    def post(self, admin_code, country_code):
        data = Admin.parser.parse_args()

        if AdminModel.find_by_code_and_country(admin_code, country_code):
            return {
                'message':
                "A '{}' admin code already exists for country with code '{}'.".
                format(admin_code, country_code)
            }, 400

        entry = AdminModel(admin_code, country_code, data['description'])
        try:
            entry.save_to_db()
        except:
            {'message': 'Something went wrong inserting the admin.'}, 500
        return entry.json(), 201