stages/otp_*: fix linting

This commit is contained in:
Jens Langhammer 2020-06-30 16:12:19 +02:00
parent d2bf579ff6
commit 2ca5e1eedb
3 changed files with 9 additions and 5 deletions

View File

@ -1,6 +1,6 @@
"""OTP Static forms""" """OTP Static forms"""
from django import forms from django import forms
from django.utils.translation import gettext_lazy as _
from passbook.stages.otp_static.models import OTPStaticStage from passbook.stages.otp_static.models import OTPStaticStage
@ -12,7 +12,7 @@ class SetupForm(forms.Form):
def __init__(self, tokens, *args, **kwargs): def __init__(self, tokens, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
print(tokens) print(tokens)
self.fields['tokens'].choices = [(x.token, x.token) for x in tokens] self.fields["tokens"].choices = [(x.token, x.token) for x in tokens]
class OTPStaticStageForm(forms.ModelForm): class OTPStaticStageForm(forms.ModelForm):

View File

@ -42,7 +42,11 @@ class OTPStaticStageView(FormView, StageView):
if SESSION_STATIC_DEVICE not in self.request.session: if SESSION_STATIC_DEVICE not in self.request.session:
device = StaticDevice(user=user, confirmed=True) device = StaticDevice(user=user, confirmed=True)
tokens = [StaticToken(device=device, token=StaticToken.random_token()) for _ in range(0, stage.token_count)] tokens = []
for _ in range(0, stage.token_count):
tokens.append(
StaticToken(device=device, token=StaticToken.random_token())
)
self.request.session[SESSION_STATIC_DEVICE] = device self.request.session[SESSION_STATIC_DEVICE] = device
self.request.session[SESSION_STATIC_TOKENS] = tokens self.request.session[SESSION_STATIC_TOKENS] = tokens
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
@ -51,7 +55,8 @@ class OTPStaticStageView(FormView, StageView):
"""Verify OTP Token""" """Verify OTP Token"""
device: StaticDevice = self.request.session[SESSION_STATIC_DEVICE] device: StaticDevice = self.request.session[SESSION_STATIC_DEVICE]
device.save() device.save()
[x.save() for x in self.request.session[SESSION_STATIC_TOKENS]] for token in self.request.session[SESSION_STATIC_TOKENS]:
token.save()
del self.request.session[SESSION_STATIC_DEVICE] del self.request.session[SESSION_STATIC_DEVICE]
del self.request.session[SESSION_STATIC_TOKENS] del self.request.session[SESSION_STATIC_TOKENS]
return self.executor.stage_ok() return self.executor.stage_ok()

View File

@ -9,7 +9,6 @@ from lxml.etree import tostring # nosec
from qrcode import QRCode from qrcode import QRCode
from qrcode.image.svg import SvgFillImage from qrcode.image.svg import SvgFillImage
from structlog import get_logger from structlog import get_logger
from django_otp.plugins.otp_totp.models import TOTPDevice
from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER from passbook.flows.planner import PLAN_CONTEXT_PENDING_USER
from passbook.flows.stage import StageView from passbook.flows.stage import StageView