Skip to content

Commit

Permalink
Merge pull request #40 from software-students-spring2024/authentication
Browse files Browse the repository at this point in the history
Set up the base for authentication
  • Loading branch information
shriyakalakata authored Feb 25, 2024
2 parents c11bbf8 + 75d19ad commit 7895db5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
pymongo = "*"
flask = "*"
python-dotenv = "*"

[dev-packages]

Expand Down
19 changes: 18 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pymongo
from pymongo import MongoClient
import authentication

load_dotenv()

Expand All @@ -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]
Expand All @@ -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("/<username>/decks")
def allDecks(username):
Expand Down Expand Up @@ -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)
app.run(port=FLASK_PORT)
9 changes: 9 additions & 0 deletions authentication.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
</form>
</div>

{% endblock %}
{% endblock %}

0 comments on commit 7895db5

Please sign in to comment.