mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
增加关闭两步验证的 api
This commit is contained in:
parent
2222a56d0a
commit
0f8dedb540
@ -86,5 +86,5 @@ class UserProfileSerializer(serializers.ModelSerializer):
|
||||
"rank", "accepted_number", "submissions_number", "problems_status", "phone_number", "school", "student_id"]
|
||||
|
||||
|
||||
class ApplyTwoFactorAuthSerializer(serializers.Serializer):
|
||||
class TwoFactorAuthCodeSerializer(serializers.Serializer):
|
||||
code = serializers.IntegerField()
|
||||
|
@ -27,7 +27,7 @@ from .serializers import (UserLoginSerializer, UserRegisterSerializer,
|
||||
UserSerializer, EditUserSerializer,
|
||||
ApplyResetPasswordSerializer, ResetPasswordSerializer,
|
||||
SSOSerializer, EditUserProfileSerializer,
|
||||
UserProfileSerializer, ApplyTwoFactorAuthSerializer)
|
||||
UserProfileSerializer, TwoFactorAuthCodeSerializer)
|
||||
|
||||
from .decorators import super_admin_required
|
||||
|
||||
@ -405,7 +405,7 @@ class TwoFactorAuthAPIView(APIView):
|
||||
"""
|
||||
开启两步验证
|
||||
"""
|
||||
serializer = ApplyTwoFactorAuthSerializer(data=request.data)
|
||||
serializer = TwoFactorAuthCodeSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
code = serializer.data["code"]
|
||||
user = request.user
|
||||
@ -416,4 +416,18 @@ class TwoFactorAuthAPIView(APIView):
|
||||
else:
|
||||
return error_response(u"验证码错误")
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
@login_required
|
||||
def put(self, request):
|
||||
serializer = TwoFactorAuthCodeSerializer(data=request.data)
|
||||
if serializer.is_valid():
|
||||
user = request.user
|
||||
code = serializer.data["code"]
|
||||
if OtpAuth(user.tfa_token).valid_totp(code):
|
||||
user.two_factor_auth = False
|
||||
user.save()
|
||||
else:
|
||||
return error_response(u"验证码错误")
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
Loading…
Reference in New Issue
Block a user