From 77016fdef4c44d9cb4c7372903a90a9b017328b8 Mon Sep 17 00:00:00 2001 From: iltenahmet Date: Sat, 2 Mar 2024 15:42:41 -0500 Subject: [PATCH] Add logout buttons --- app.py | 4 ++++ authentication.py | 6 ++++-- templates/card.html | 35 +++++++++++++++++++---------------- templates/decks.html | 10 +++++++--- templates/macros.html | 5 +++++ 5 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 templates/macros.html diff --git a/app.py b/app.py index 05519f8..c0e0793 100644 --- a/app.py +++ b/app.py @@ -31,6 +31,10 @@ def login(): def signup(): return auth_signup() +@app.route('/logout', methods=["GET", "POST"]) +def logout(): + return auth_logout() + @app.route("//decks") def allDecks(username): if username == "guest": diff --git a/authentication.py b/authentication.py index 9dfbb59..e29148f 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, current_user +from flask_login import LoginManager, UserMixin, login_user, current_user, logout_user from db import * from pymongo import * from werkzeug.security import generate_password_hash, check_password_hash @@ -71,5 +71,7 @@ def auth_signup(): else: return render_template('signup.html', username_taken=False, passwords_dont_match=False) - +def auth_logout(): + logout_user() + return redirect('/') diff --git a/templates/card.html b/templates/card.html index dc4d6e7..43ecf9c 100644 --- a/templates/card.html +++ b/templates/card.html @@ -18,22 +18,25 @@

START

{% if isAuth %} - - - -
- - -
- - + + + +
+ + +
+ + + + {% from 'macros.html' import logout %} + {{ logout() }} {% endif %} diff --git a/templates/decks.html b/templates/decks.html index f238ace..6f9cc0d 100644 --- a/templates/decks.html +++ b/templates/decks.html @@ -45,9 +45,9 @@

{{ deck.title }}

{% if isAuth %} - + +{% endmacro %}