Purpose: Create a Python function decorator that protects login routes, checking a user's authorization level.
The goal of this exercise is to replace this conditional code that you added in Exercise 6.2:
with something cleaner, like this:
This cleaner approach will be useful in your project where several routes need protecting, because those if statements get tedious. To make it happen, you will create a function decorator called access_required.
Function Decorator for Authorization: .
Function Decorators: For those not familiar with function decorators, a function decorator is a function that takes a function as a parameter and returns a function. It creates a wrapping effect, so that a "decorated" function can run code before the function is called and determine whether the function is called. Flask uses this in @app.route, which runs pattern-matching on a web request to determine whether to call your function and returns a server response instead of calling your function when something goes wrong with the web request. To learn more about function decorators, feel free to read this resource.
Now, add @access_required(2) as shown above to protect the "/secret" route.
To test, Then change the access required to 1 and 3 and see what happens when "Get Secret Bat Information"
Take time to analyze why this works the way it does. You will need to incorporate these concepts into your Project Part 6.