Skip to content

Commit

Permalink
Merge pull request #74 from software-students-spring2024/logout
Browse files Browse the repository at this point in the history
Add logout buttons
  • Loading branch information
shriyakalakata authored Mar 2, 2024
2 parents 7e8ab98 + 77016fd commit d8d02e4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def login():
def signup():
return auth_signup()

@app.route('/logout', methods=["GET", "POST"])
def logout():
return auth_logout()

@app.route("/<username>/decks")
def allDecks(username):
if username == "guest":
Expand Down
6 changes: 4 additions & 2 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, 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
Expand Down Expand Up @@ -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('/')

35 changes: 19 additions & 16 deletions templates/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,25 @@ <h3 id="next-question"> START </h3>

{% if isAuth %}

<button id="add-card-button" class="button2" >Add Card</button>
<button id="edit-card-button" class="button2" style="display: none">Edit</button>

<form method="post" id="delete-form">
<input type="hidden" name="question" id="delete-form-question" value=""></input>
<button id="delete-card-button" class="button2" style="display: none">Delete Card</button>
</form>

<form method="post" id="card-form" style="display: none">
<svg id="close-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" width="120px" height="120px">
<circle fill="#63514F" cx="15" cy="15" r="10" />
<path fill="#D9D9D9" d="M15,3C8.373,3,3,8.373,3,15c0,6.627,5.373,12,12,12s12-5.373,12-12C27,8.373,21.627,3,15,3z M16.414,15 c0,0,3.139,3.139,3.293,3.293c0.391,0.391,0.391,1.024,0,1.414c-0.391,0.391-1.024,0.391-1.414,0C18.139,19.554,15,16.414,15,16.414 s-3.139,3.139-3.293,3.293c-0.391,0.391-1.024,0.391-1.414,0c-0.391-0.391-0.391-1.024,0-1.414C10.446,18.139,13.586,15,13.586,15 s-3.139-3.139-3.293-3.293c-0.391-0.391-0.391-1.024,0-1.414c0.391-0.391,1.024-0.391,1.414,0C11.861,10.446,15,13.586,15,13.586 s3.139-3.139,3.293-3.293c0.391-0.391,1.024-0.391,1.414,0c0.391,0.391,0.391,1.024,0,1.414C19.554,11.861,16.414,15,16.414,15z"/>
</svg>
<textarea name="question" required></textarea>
<button class="button2">Done</button>
</form>
<button id="add-card-button" class="button2" >Add Card</button>
<button id="edit-card-button" class="button2" style="display: none">Edit</button>

<form method="post" id="delete-form">
<input type="hidden" name="question" id="delete-form-question" value=""></input>
<button id="delete-card-button" class="button2" style="display: none">Delete Card</button>
</form>

<form method="post" id="card-form" style="display: none">
<svg id="close-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 30 30" width="120px" height="120px">
<circle fill="#63514F" cx="15" cy="15" r="10" />
<path fill="#D9D9D9" d="M15,3C8.373,3,3,8.373,3,15c0,6.627,5.373,12,12,12s12-5.373,12-12C27,8.373,21.627,3,15,3z M16.414,15 c0,0,3.139,3.139,3.293,3.293c0.391,0.391,0.391,1.024,0,1.414c-0.391,0.391-1.024,0.391-1.414,0C18.139,19.554,15,16.414,15,16.414 s-3.139,3.139-3.293,3.293c-0.391,0.391-1.024,0.391-1.414,0c-0.391-0.391-0.391-1.024,0-1.414C10.446,18.139,13.586,15,13.586,15 s-3.139-3.139-3.293-3.293c-0.391-0.391-0.391-1.024,0-1.414c0.391-0.391,1.024-0.391,1.414,0C11.861,10.446,15,13.586,15,13.586 s3.139-3.139,3.293-3.293c0.391-0.391,1.024-0.391,1.414,0c0.391,0.391,0.391,1.024,0,1.414C19.554,11.861,16.414,15,16.414,15z"/>
</svg>
<textarea name="question" required></textarea>
<button class="button2">Done</button>
</form>

{% from 'macros.html' import logout %}
{{ logout() }}

{% endif %}

Expand Down
10 changes: 7 additions & 3 deletions templates/decks.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ <h3>{{ deck.title }}</h3>
</script>

{% if isAuth %}
<button class="add-deck">
<h3> + </h3>
</button>
<button class="add-deck">
<h3> + </h3>
</button>

<form action="{{ url_for('createDeck', username=username) }}" method="post" class="add-deck-form" style="display: none">
<p>x</p>
Expand All @@ -70,7 +70,11 @@ <h3> + </h3>
document.querySelector(".add-deck-form").style.display="none"
})
</script>

{% from 'macros.html' import logout %}
{{ logout() }}
{% endif %}


{% endblock %}

5 changes: 5 additions & 0 deletions templates/macros.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro logout() %}
<form action="{{ url_for('logout') }}" method="post">
<button type="submit" class="button2"> Logout </button>
</form>
{% endmacro %}

0 comments on commit d8d02e4

Please sign in to comment.