Draft: Two factor auth #118

Open
sonny wants to merge 9 commits from two-factor-auth into development
3 changed files with 18 additions and 5 deletions
Showing only changes of commit 79bff5505e - Show all commits

View file

@ -10,7 +10,6 @@ from two_factor.views import (
ProfileView,
QRGeneratorView,
SetupCompleteView,
SetupView,
)
from newsreader.accounts.views import (
@ -33,6 +32,7 @@ from newsreader.accounts.views import (
RegistrationCompleteView,
RegistrationView,
SettingsView,
SetupView,
TwitterAuthRedirectView,
TwitterRevokeRedirectView,
TwitterTemplateView,

View file

@ -1,4 +1,4 @@
from newsreader.accounts.views.auth import LoginView, LogoutView
from newsreader.accounts.views.auth import LoginView, LogoutView, SetupView
from newsreader.accounts.views.favicon import FaviconRedirectView
from newsreader.accounts.views.integrations import (
IntegrationsView,

View file

@ -1,17 +1,30 @@
from django.contrib.auth import views as django_views
from django.shortcuts import redirect
from django.urls import reverse_lazy
from two_factor.views.core import LoginView as TwoFactorLoginView
from two_factor.views.core import SetupView as TwoFactorSetupView
class LoginView(TwoFactorLoginView):
redirect_authenticated_user = True
template_name = "accounts/views/login.html"
def post(self, *args, **kwargs):
print(self.request.POST)
return super().post(*args, **kwargs)
def done(self, form_list, **kwargs):
response = super().done(form_list, **kwargs)
user = self.get_user()
if not user.phonedevice_set.exists():
return redirect("accounts:two_factor:setup")
return response
class LogoutView(django_views.LogoutView):
next_page = reverse_lazy("accounts:login")
class SetupView(TwoFactorSetupView):
success_url = "accounts:two_factor:setup_complete"
qrcode_url = "accounts:two_factor:qr"