This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2019-10-10 12:05:16 +00:00
|
|
|
"""recovery views"""
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.contrib.auth import login
|
|
|
|
from django.http import Http404, HttpRequest, HttpResponse
|
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
|
|
|
from django.utils.translation import gettext as _
|
|
|
|
from django.views import View
|
|
|
|
|
|
|
|
from passbook.core.models import Nonce
|
|
|
|
|
|
|
|
|
|
|
|
class UseNonceView(View):
|
|
|
|
"""Use nonce to login"""
|
|
|
|
|
|
|
|
def get(self, request: HttpRequest, uuid: str) -> HttpResponse:
|
|
|
|
"""Check if nonce exists, log user in and delete nonce."""
|
|
|
|
nonce: Nonce = get_object_or_404(Nonce, pk=uuid)
|
|
|
|
if nonce.is_expired:
|
|
|
|
nonce.delete()
|
|
|
|
raise Http404
|
2019-12-31 11:51:16 +00:00
|
|
|
login(request, nonce.user, backend="django.contrib.auth.backends.ModelBackend")
|
2019-10-10 12:05:16 +00:00
|
|
|
nonce.delete()
|
|
|
|
messages.warning(request, _("Used recovery-link to authenticate."))
|
2019-12-31 11:51:16 +00:00
|
|
|
return redirect("passbook_core:overview")
|