From 43b5a67caba17aebd54c08ec75842795761be530 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 28 Dec 2021 13:05:41 +0100 Subject: [PATCH] Create logout view --- .../templates/ereuse_devicehub/base_site.html | 14 ++------------ ereuse_devicehub/views.py | 9 ++++++++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html index b68d5635..d1c50e43 100644 --- a/ereuse_devicehub/templates/ereuse_devicehub/base_site.html +++ b/ereuse_devicehub/templates/ereuse_devicehub/base_site.html @@ -185,7 +185,7 @@
  • - + My Profile @@ -194,16 +194,6 @@
  • -
  • - - - Account Settings - -
  • -
  • - -
  • -
  • @@ -215,7 +205,7 @@
  • - + Sign Out diff --git a/ereuse_devicehub/views.py b/ereuse_devicehub/views.py index 3c5b28d0..84397ce7 100644 --- a/ereuse_devicehub/views.py +++ b/ereuse_devicehub/views.py @@ -1,7 +1,7 @@ import flask from flask import Blueprint from flask.views import View -from flask_login import login_required, login_user +from flask_login import login_required, login_user, logout_user from ereuse_devicehub.forms import LoginForm from ereuse_devicehub.resources.user.models import User @@ -32,6 +32,12 @@ class LoginView(View): return flask.render_template('ereuse_devicehub/user_login.html', form=form) +class LogoutView(View): + def dispatch_request(self): + logout_user() + return flask.redirect(flask.url_for('core.login')) + + class UserProfileView(View): decorators = [login_required] template_name = 'ereuse_devicehub/user_profile.html' @@ -42,4 +48,5 @@ class UserProfileView(View): core.add_url_rule('/login/', view_func=LoginView.as_view('login')) +core.add_url_rule('/logout/', view_func=LogoutView.as_view('logout')) core.add_url_rule('/profile/', view_func=UserProfileView.as_view('user-profile'))