make pylint stop grumbling

This commit is contained in:
Hugh Rundle 2022-09-11 21:36:30 +10:00
parent 1d13f0ab4f
commit 9d12b7caff
3 changed files with 11 additions and 9 deletions

View file

@ -4,12 +4,12 @@ from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
import pyotp
from bookwyrm import models from bookwyrm import models
from bookwyrm.models.fields import ClearableFileInputWithWarning from bookwyrm.models.fields import ClearableFileInputWithWarning
from .custom_form import CustomForm from .custom_form import CustomForm
import pyotp
# pylint: disable=missing-class-docstring # pylint: disable=missing-class-docstring
class EditUserForm(CustomForm): class EditUserForm(CustomForm):
class Meta: class Meta:

View file

@ -29,6 +29,7 @@ class Login(View):
} }
return TemplateResponse(request, "landing/login.html", data) return TemplateResponse(request, "landing/login.html", data)
#pylint: disable=too-many-return-statements
@sensitive_variables("password") @sensitive_variables("password")
@method_decorator(sensitive_post_parameters("password")) @method_decorator(sensitive_post_parameters("password"))
def post(self, request): def post(self, request):
@ -52,7 +53,7 @@ class Login(View):
user = authenticate(request, username=username, password=password) user = authenticate(request, username=username, password=password)
if user is not None: if user is not None:
# if 2fa is set, don't log them in until they enter the right code # if 2fa is set, don't log them in until they enter the right code
if user.two_factor_auth == True: if user.two_factor_auth is True:
form = forms.Confirm2FAForm(request.GET, user) form = forms.Confirm2FAForm(request.GET, user)
return TemplateResponse( return TemplateResponse(
request, request,
@ -66,7 +67,7 @@ class Login(View):
if request.POST.get("first_login"): if request.POST.get("first_login"):
return set_language(user, redirect("get-started-profile")) return set_language(user, redirect("get-started-profile"))
if user.two_factor_auth == None: if user.two_factor_auth is None:
# set to false so this page doesn't pop up again # set to false so this page doesn't pop up again
user.two_factor_auth = False user.two_factor_auth = False
user.save(broadcast=False, update_fields=["two_factor_auth"]) user.save(broadcast=False, update_fields=["two_factor_auth"])

View file

@ -1,8 +1,8 @@
""" class views for 2FA management """ """ class views for 2FA management """
import time
import pyotp import pyotp
import qrcode import qrcode
import qrcode.image.svg import qrcode.image.svg
import time
from django.contrib.auth import login from django.contrib.auth import login
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
@ -52,10 +52,10 @@ class Edit2FA(View):
provisioning_url = pyotp.totp.TOTP(otp_secret).provisioning_uri( provisioning_url = pyotp.totp.TOTP(otp_secret).provisioning_uri(
name=user.localname, issuer_name=DOMAIN name=user.localname, issuer_name=DOMAIN
) )
qr = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage) qr_code = qrcode.QRCode(image_factory=qrcode.image.svg.SvgPathImage)
qr.add_data(provisioning_url) qr_code.add_data(provisioning_url)
qr.make(fit=True) qr_code.make(fit=True)
img = qr.make_image(attrib={"fill": "black"}) img = qr_code.make_image(attrib={"fill": "black"})
return img.to_string() return img.to_string()
@ -119,4 +119,5 @@ class Prompt2FA(View):
"""Alert user to the existence of 2FA""" """Alert user to the existence of 2FA"""
def get(self, request): def get(self, request):
"""Alert user to the existence of 2FA"""
return TemplateResponse(request, "two_factor_auth/two_factor_prompt.html") return TemplateResponse(request, "two_factor_auth/two_factor_prompt.html")