Question 10
Consider the following flask application running on the base URL and is accessed through a browser. Select the correct option(s).
from flask import Flask, abort, request
app = Flask(__name__)
users = { 1 : {"Name": "Ritu", "role": "Admin", "access": True}, 2 : {"Name": "Ramesh", "role": "User", "access": True}, 3 : {"Name": "Tejas", "role": "Admin", "access": True}, 4 : {"Name": "Manisha", "role": "User", "access": False} }
@app.route('/login')def auth(): cred = request.args if users[int(cred["id"])].get("access"): id = int(cred["id"]) user = users[id] return "Welcome, "+ user.get("Name")+", you have"+user.get("role")+" access" else: abort(403)
@app.errorhandler(403)def no_access(error): return "Looks like you are not an authorized user!"
app.run(debug = True)