Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More card crud #55

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading