From a68e5c3271eb7160528662f534a52439b24ea3c6 Mon Sep 17 00:00:00 2001 From: al6862 Date: Wed, 28 Feb 2024 14:22:46 -0500 Subject: [PATCH 1/2] log in and sign up functions redirect to decks --- authentication.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/authentication.py b/authentication.py index 1f6a91f..7c1628d 100644 --- a/authentication.py +++ b/authentication.py @@ -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 @@ -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: @@ -66,7 +66,7 @@ def auth_signup(): db['users'].insert_one({"user_id": user.id, "password": user.password}) 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) From 338f17d732280150bc88af2198329e8ba6c4ce24 Mon Sep 17 00:00:00 2001 From: al6862 Date: Wed, 28 Feb 2024 14:35:27 -0500 Subject: [PATCH 2/2] added mainDecks and personalDecks to signup --- app.py | 7 +++---- authentication.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index 759ef86..c456866 100644 --- a/app.py +++ b/app.py @@ -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("//") diff --git a/authentication.py b/authentication.py index 7c1628d..f094140 100644 --- a/authentication.py +++ b/authentication.py @@ -63,7 +63,7 @@ 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('/' + user_id + '/decks')