Skip to content

Commit

Permalink
return otp_bypass_token_exists flag
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Oct 2, 2023
1 parent 276e681 commit b123c05
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions backend/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from codeforlife.mixins import CronMixin
from codeforlife.request import HttpRequest
from codeforlife.user.models import AuthFactor
from common.models import UserSession
from django.contrib.auth import login
from django.contrib.auth.views import LoginView as _LoginView
Expand Down Expand Up @@ -58,15 +59,21 @@ def form_valid(self, form: BaseAuthForm):
# Save session (with data).
self.request.session.save()

return JsonResponse(
{
"auth_factors": list(
self.request.user.session.session_auth_factors.values_list(
"auth_factor__type", flat=True
)
response_data = {
"auth_factors": list(
self.request.user.session.session_auth_factors.values_list(
"auth_factor__type", flat=True
)
}
)
),
"otp_bypass_token_exists": False,
}

if AuthFactor.Type.OTP in response_data["auth_factors"]:
response_data[
"otp_bypass_token_exists"
] = self.request.user.otp_bypass_tokens.exists()

return JsonResponse(response_data)

def form_invalid(self, form: BaseAuthForm):
return JsonResponse(form.errors, status=status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit b123c05

Please sign in to comment.