Create logout view

This commit is contained in:
Santiago L 2021-12-28 13:05:41 +01:00
parent 734cd8e6e5
commit 43b5a67cab
2 changed files with 10 additions and 13 deletions

View File

@ -185,7 +185,7 @@
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="users-profile.html">
<a class="dropdown-item d-flex align-items-center" href="{{ url_for('core.user-profile') }}">
<i class="bi bi-person"></i>
<span>My Profile</span>
</a>
@ -194,16 +194,6 @@
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="users-profile.html">
<i class="bi bi-gear"></i>
<span>Account Settings</span>
</a>
</li>
<li>
<hr class="dropdown-divider">
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="pages-faq.html">
<i class="bi bi-question-circle"></i>
@ -215,7 +205,7 @@
</li>
<li>
<a class="dropdown-item d-flex align-items-center" href="#">
<a class="dropdown-item d-flex align-items-center" href="{{ url_for('core.logout') }}">
<i class="bi bi-box-arrow-right"></i>
<span>Sign Out</span>
</a>

View File

@ -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'))