Skip to content

Commit

Permalink
added log out feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan-Sell committed Nov 17, 2024
1 parent 0b675f2 commit e1c0718
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Flask, flash, jsonify, redirect, render_template, request, url_for
from flask_login import LoginManager, login_required, login_user
from flask_login import LoginManager, login_required, login_user, logout_user

from src.forms.task_form import AddTaskForm, DeleteTaskForm, EditTaskForm
from src.forms.user_forms import LogInForm, RegisterForm
Expand Down Expand Up @@ -58,6 +58,14 @@ def login():
return render_template("login.html", form=form)


@app.route("/logout")
@login_required
def logout():
logout_user()
flash("You have successfully logged out.", "info")
return redirect(url_for("login"))


@app.route("/dashboard")
@login_required
def dashboard():
Expand Down
3 changes: 2 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<a class="dropdown-item" href="{{ url_for('add_task', user_id=current_user.id) }}">Add Task</a>
<a class="dropdown-item" href="{{ url_for('edit_task', user_id=current_user.id) }}">Edit Task</a>
<a class="dropdown-item" href="{{ url_for('delete_task', user_id=current_user.id) }}">Delete Task</a>
<!-- TODO: Change password -->
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="{{ url_for('logout') }}">Log Out</a>
</div>
</li>
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2 class="mt-2" style="font-family: 'Brush Script MT', cursive; font-size: 2.5r
</p>
</form>
<p class="text-center mt-4" style="font-size: 0.9rem; color: #888;">
Because you're always on top of the mountain (or at least your todo list).
Because you're always on top of the mountain (or at least your to-do list).
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2 class="mt-2" style="font-family: 'Brush Script MT', cursive; font-size: 2.5r
</p>
</form>
<p class="text-center mt-4" style="font-size: 0.9rem; color: #888;">
Because you're always on top of the mountain (or at least your todo list).
Because you're always on top of the mountain (or at least your to-do list).
</p>
</div>
</div>
Expand Down

0 comments on commit e1c0718

Please sign in to comment.