fix settings
This commit is contained in:
parent
9c15f4ba88
commit
0deb78a9af
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
import pyotp
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import login
|
||||
from django.db import IntegrityError
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
@ -14,7 +15,7 @@ from rest_framework.views import APIView
|
|||
from rest_framework.serializers import (
|
||||
ModelSerializer,
|
||||
SerializerMethodField,
|
||||
ReadOnlyField
|
||||
ReadOnlyField,
|
||||
)
|
||||
|
||||
from accounts.utils import is_root_user
|
||||
|
@ -56,8 +57,8 @@ class CheckCredsV2(KnoxLoginView):
|
|||
return notify_error("Bad credentials")
|
||||
|
||||
# block local logon if configured
|
||||
settings = get_core_settings()
|
||||
if not user.is_superuser and settings.block_local_user_logon:
|
||||
core_settings = get_core_settings()
|
||||
if not user.is_superuser and core_settings.block_local_user_logon:
|
||||
return notify_error("Bad credentials")
|
||||
|
||||
# if totp token not set modify response to notify frontend
|
||||
|
@ -84,8 +85,8 @@ class LoginViewV2(KnoxLoginView):
|
|||
return notify_error("Bad credentials")
|
||||
|
||||
# block local logon if configured
|
||||
settings = get_core_settings()
|
||||
if not user.is_superuser and settings.block_local_user_logon:
|
||||
core_settings = get_core_settings()
|
||||
if not user.is_superuser and core_settings.block_local_user_logon:
|
||||
return notify_error("Bad credentials")
|
||||
|
||||
token = request.data["twofactor"]
|
||||
|
@ -142,8 +143,8 @@ class CheckCreds(KnoxLoginView):
|
|||
return notify_error("Bad credentials")
|
||||
|
||||
# block local logon if configured
|
||||
settings = get_core_settings()
|
||||
if not user.is_superuser and settings.block_local_user_logon:
|
||||
core_settings = get_core_settings()
|
||||
if not user.is_superuser and core_settings.block_local_user_logon:
|
||||
return notify_error("Bad credentials")
|
||||
|
||||
# if totp token not set modify response to notify frontend
|
||||
|
@ -173,8 +174,8 @@ class LoginView(KnoxLoginView):
|
|||
return notify_error("Bad credentials")
|
||||
|
||||
# block local logon if configured
|
||||
settings = get_core_settings()
|
||||
if not user.is_superuser and settings.block_local_user_logon:
|
||||
core_settings = get_core_settings()
|
||||
if not user.is_superuser and core_settings.block_local_user_logon:
|
||||
return notify_error("Bad credentials")
|
||||
|
||||
token = request.data["twofactor"]
|
||||
|
@ -213,6 +214,7 @@ class GetDeleteActiveLoginSessionsPerUser(APIView):
|
|||
|
||||
class TokenSerializer(ModelSerializer):
|
||||
user = ReadOnlyField(source="user.username")
|
||||
|
||||
class Meta:
|
||||
model = AuthToken
|
||||
fields = (
|
||||
|
@ -222,15 +224,17 @@ class GetDeleteActiveLoginSessionsPerUser(APIView):
|
|||
"expiry",
|
||||
)
|
||||
|
||||
|
||||
def get(self, request, pk):
|
||||
tokens = get_object_or_404(User, pk=pk).auth_token_set.filter(expiry__gt=djangotime.now())
|
||||
tokens = get_object_or_404(User, pk=pk).auth_token_set.filter(
|
||||
expiry__gt=djangotime.now()
|
||||
)
|
||||
|
||||
return Response(self.TokenSerializer(tokens, many=True).data)
|
||||
|
||||
|
||||
def delete(self, request, pk):
|
||||
tokens = get_object_or_404(User, pk=pk).auth_token_set.filter(expiry__gt=djangotime.now())
|
||||
tokens = get_object_or_404(User, pk=pk).auth_token_set.filter(
|
||||
expiry__gt=djangotime.now()
|
||||
)
|
||||
|
||||
tokens.delete()
|
||||
return Response("ok")
|
||||
|
@ -246,6 +250,7 @@ class DeleteActiveLoginSession(APIView):
|
|||
|
||||
return Response("ok")
|
||||
|
||||
|
||||
class GetAddUsers(APIView):
|
||||
permission_classes = [IsAuthenticated, AccountsPerms]
|
||||
|
||||
|
@ -264,7 +269,7 @@ class GetAddUsers(APIView):
|
|||
"display": account.get_provider_account().to_str(),
|
||||
"last_login": account.last_login,
|
||||
"date_joined": account.date_joined,
|
||||
"extra_data": account.extra_data
|
||||
"extra_data": account.extra_data,
|
||||
}
|
||||
for account in accounts
|
||||
]
|
||||
|
@ -283,7 +288,7 @@ class GetAddUsers(APIView):
|
|||
"role",
|
||||
"block_dashboard_login",
|
||||
"date_format",
|
||||
"social_accounts"
|
||||
"social_accounts",
|
||||
]
|
||||
|
||||
def get(self, request):
|
||||
|
|
Loading…
Reference in New Issue