| 1 |
from django.contrib import messages |
| 2 |
from django.http import HttpRequest |
| 3 |
|
| 4 |
from allauth.account.internal.flows.password_reset_by_code import ( |
| 5 |
PASSWORD_RESET_VERIFICATION_SESSION_KEY, |
| 6 |
) |
| 7 |
from allauth.account.internal.stagekit import clear_login |
| 8 |
|
| 9 |
|
| 10 |
def logout(request: HttpRequest, *, show_message: bool = True) -> None: |
| 11 |
from allauth.account.adapter import get_adapter |
| 12 |
from allauth.account.views import INTERNAL_RESET_SESSION_KEY |
| 13 |
|
| 14 |
if request.user.is_authenticated: |
| 15 |
adapter = get_adapter() |
| 16 |
if show_message: |
| 17 |
adapter.add_message( |
| 18 |
request, messages.SUCCESS, "account/messages/logged_out.txt" |
| 19 |
) |
| 20 |
adapter.logout(request) |
| 21 |
clear_login(request) |
| 22 |
request.session.pop(PASSWORD_RESET_VERIFICATION_SESSION_KEY, None) |
| 23 |
request.session.pop(INTERNAL_RESET_SESSION_KEY, None) |