diff --git a/python/requirements.txt b/python/requirements.txt index d1c8e63..f741135 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -1,2 +1,3 @@ flask -pylint==2.16.1 \ No newline at end of file +pylint==2.16.1 +gunicorn diff --git a/python/run.py b/python/run.py index e6836b3..598cdf3 100644 --- a/python/run.py +++ b/python/run.py @@ -1,5 +1,17 @@ +""" +This module is used to call the flask code. +""" + from src.main import app +# Flask has the built-in Werkzeug server. +# Only run the dev server if this file is executed directly + +# host='0.0.0.0' -> Exposes the app to all network interfaces, not just localhost. +# port=8080 -> Binds the app to port 8080. +# debug=True -> Enables debug mode, which provides automatic reload + debugger. +# threaded=True -> Enables multi-threading, so one process can handle multiple requests concurrently + if __name__ == "__main__": app.debug = True app.secret_key = "any random string" diff --git a/python/src/main.py b/python/src/main.py index 8eb9bdc..83afbe6 100644 --- a/python/src/main.py +++ b/python/src/main.py @@ -9,10 +9,12 @@ @app.route("/") def index(): + """ Brief summary of what the function does. """ return render_template("index.html") @app.route("/login", methods=["GET", "POST"]) def login(): + """ Brief summary of what the function does. """ if request.method == "POST": if valid_login(request.form["t1"], request.form["t2"]): session["username"] = request.form["t1"] @@ -24,13 +26,16 @@ def login(): @app.route("/home") def home(): + """ Brief summary of what the function does. """ return render_template("home.html", user = session["username"]) @app.route("/logout") def logout(): + """ Brief summary of what the function does. """ session.pop("username", None) return redirect(url_for("login")) @app.route("/maintenance") def maintenance(): + """ Brief summary of what the function does. """ return "Sorry, we are under maintenance. Try to login with same username and password." diff --git a/python/src/validlogin.py b/python/src/validlogin.py index a7e8987..c161c99 100644 --- a/python/src/validlogin.py +++ b/python/src/validlogin.py @@ -6,14 +6,15 @@ def valid_login(username, password): """ Checks the validity of the login credentials. - Parameters: + Args: username (str): The username of the user. password (str): The password of the user. Returns: bool: returns the validity of the login """ - if((username == password) and username != "" and password != ""): + + if (username == password) and username != "" and password != "": return True else: return False