diff --git a/Pipfile b/Pipfile index 4e871b1..03c6b68 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] pymongo = "*" flask = "*" +python-dotenv = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index a917fba..616cf0f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "9b7939a21a860b0c3f14a6a5fd131e51d50b87d5de8b6a7772d1b7c6555eb81b" + "sha256": "2845750caf44933171e5c0fa0a3d3693e3cbe3cb10b25811beee31ba0c5373a8" }, "pipfile-spec": 6, "requires": { @@ -32,6 +32,14 @@ "markers": "python_version >= '3.7'", "version": "==8.1.7" }, + "colorama": { + "hashes": [ + "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", + "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6" + ], + "markers": "platform_system == 'Windows'", + "version": "==0.4.6" + }, "dnspython": { "hashes": [ "sha256:5ef3b9680161f6fa89daf8ad451b5f1a33b18ae8a1c6778cdf4b43f08c0a6e50", @@ -220,6 +228,15 @@ "markers": "python_version >= '3.7'", "version": "==4.6.2" }, + "python-dotenv": { + "hashes": [ + "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca", + "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a" + ], + "index": "pypi", + "markers": "python_version >= '3.8'", + "version": "==1.0.1" + }, "werkzeug": { "hashes": [ "sha256:507e811ecea72b18a404947aded4b3390e1db8f826b494d76550ef45bb3b1dcc", diff --git a/app.py b/app.py index d8532ab..2a497ca 100644 --- a/app.py +++ b/app.py @@ -3,6 +3,7 @@ import os import pymongo from pymongo import MongoClient +import authentication load_dotenv() @@ -11,6 +12,12 @@ uri = os.getenv("MONGO_URI") db_name = os.getenv("MONGO_DBNAME") +# Display error message if mongoDB environment is not set up +if not uri or not db_name: + error_message = "MongoDB environment is not set up. Please check your environment variables." + app.logger.error(error_message) + raise EnvironmentError(error_message) + # Create a new client and connect to the server client = MongoClient(uri) db = client[db_name] @@ -21,24 +28,17 @@ print("Connected to MongoDB!") except Exception as e: print("MongoDB connection error:", e) - + @app.route("/") def home(): + # Note: (Ahmet) I will do these # TODO: redirect to login # TODO: redirect to sign up return render_template('start.html') -@app.route("/login", methods=["GET", "POST"]) -def login(): - # would get form fields - # would check if correct username and password - return render_template('login.html') - -@app.route("/signup", methods=["GET", "POST"]) -def signup(): - #would add user to db - #would redirect to template for login - return render_template('signup.html') +# Handle authentication related stuff in authentication.py file +app.add_url_rule('/login', methods=["GET", "POST"], view_func=authentication.login) +app.add_url_rule('/signup', methods=["GET", "POST"], view_func=authentication.signup) @app.route("//decks") def allDecks(username): @@ -78,4 +78,4 @@ def editCard(username, deckTitle, cardIndex): # run the app if __name__ == "__main__": FLASK_PORT = os.getenv("FLASK_PORT", "5000") - app.run(port=FLASK_PORT) \ No newline at end of file + app.run(port=FLASK_PORT) diff --git a/authentication.py b/authentication.py new file mode 100644 index 0000000..db3ad35 --- /dev/null +++ b/authentication.py @@ -0,0 +1,9 @@ +from flask import render_template + +def login(): + return render_template('login.html') + +def signup(): + return render_template('signup.html') + +# TODO: Handle autehentication and session management with flask-login diff --git a/templates/signup.html b/templates/signup.html index 3ed9425..03c05d4 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -11,4 +11,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %}