stages/authenticator_totp: fix key error

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-05-14 19:57:00 +02:00
parent be06adcb59
commit 5644d5f3f7
1 changed files with 6 additions and 5 deletions

View File

@ -40,10 +40,11 @@ class AuthenticatorTOTPChallengeResponse(ChallengeResponse):
def validate_code(self, code: int) -> int:
"""Validate totp code"""
if self.device is not None:
if not self.device.verify_token(code):
self.device.confirmed = False
raise ValidationError(_("Code does not match"))
if not self.device:
raise ValidationError(_("Code does not match"))
if not self.device.verify_token(code):
self.device.confirmed = False
raise ValidationError(_("Code does not match"))
return code
@ -65,7 +66,7 @@ class AuthenticatorTOTPStageView(ChallengeStageView):
def get_response_instance(self, data: QueryDict) -> ChallengeResponse:
response = super().get_response_instance(data)
response.device = self.request.session[SESSION_TOTP_DEVICE]
response.device = self.request.session.get(SESSION_TOTP_DEVICE)
return response
def get(self, request: HttpRequest, *args, **kwargs) -> HttpResponse: