Skip to content

Commit

Permalink
Merge pull request #55 from software-students-spring2024/more-card-crud
Browse files Browse the repository at this point in the history
More card crud
  • Loading branch information
gboeker authored Feb 28, 2024
2 parents 8744b2c + 338f17d commit 6a94717
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ def allDecks(username):
return render_template('decks.html', mainDecks=mainDecks)
else:
if (not current_user.is_authenticated or current_user.id != username):
# TODO: Implement proper 404 screen to redirect here.
return username + " needs to log in first."
return redirect('/login')
else:
# TODO: Redirect to the decks of the current user
return "Here would be the decks of " + current_user.id + "."
user = db.users.find_one({'user_id': current_user.id})
return render_template('decks.html', mainDecks = user['mainDecks'], personalDecks = user['personalDecks'])


@app.route("/<username>/<deckTitle>")
Expand Down
8 changes: 4 additions & 4 deletions authentication.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import render_template, request, redirect, url_for, session, flash
from flask_login import LoginManager, UserMixin, login_user
from flask_login import LoginManager, UserMixin, login_user, current_user
from db import *
from pymongo import *
from werkzeug.security import generate_password_hash, check_password_hash
Expand Down Expand Up @@ -45,7 +45,7 @@ def auth_login():
if user and user.verify_password(password):
# TODO: Redirect to the appropriate page for the logged in user
login_user(user)
return redirect('/')
return redirect('/' + user_id + '/decks')
else:
return render_template('login.html', invalid_login=True)
else:
Expand All @@ -63,10 +63,10 @@ def auth_signup():
return render_template('signup.html', username_taken=False, passwords_dont_match=True)
else:
user = User(user_id, generate_password_hash(password))
db['users'].insert_one({"user_id": user.id, "password": user.password})
db['users'].insert_one({"user_id": user.id, "password": user.password, 'mainDecks': [], 'personalDecks': []})
login_user(user)
# TODO: Redirect to the appropriate page for the logged in user
return redirect('/')
return redirect('/' + user_id + '/decks')

else:
return render_template('signup.html', username_taken=False, passwords_dont_match=False)
Expand Down

0 comments on commit 6a94717

Please sign in to comment.