2222from common .database_model_manage .database_model_manage import DatabaseModelManage
2323from common .exception .app_exception import AppApiException
2424from common .utils .common import password_encrypt , get_random_chars
25+ from common .utils .rsa_util import encrypt , decrypt
2526from maxkb .const import CONFIG
2627from users .models import User
2728
@@ -31,6 +32,9 @@ class LoginRequest(serializers.Serializer):
3132 password = serializers .CharField (required = True , max_length = 128 , label = _ ("Password" ))
3233 captcha = serializers .CharField (required = False , max_length = 64 , label = _ ('captcha' ), allow_null = True ,
3334 allow_blank = True )
35+ encryptedData = serializers .CharField (required = False , label = _ ('encryptedData' ), allow_null = True ,
36+ allow_blank = True )
37+
3438
3539
3640system_version , system_get_key = Cache_Version .SYSTEM .value
@@ -60,6 +64,10 @@ class LoginSerializer(serializers.Serializer):
6064 @staticmethod
6165 def login (instance ):
6266 username = instance .get ("username" , "" )
67+ encryptedData = instance .get ("encryptedData" , "" )
68+ if encryptedData :
69+ json_data = json .loads (decrypt (encryptedData ))
70+ instance .update (json_data )
6371 try :
6472 LoginRequest (data = instance ).is_valid (raise_exception = True )
6573 except Exception as e :
@@ -99,7 +107,7 @@ def login(instance):
99107 if captcha_cache is None or captcha .lower () != captcha_cache :
100108 raise AppApiException (1005 , _ ("Captcha code error or expiration" ))
101109
102- user = QuerySet (User ).filter (username = username , password = password ).first ()
110+ user = QuerySet (User ).filter (username = username , password = password_encrypt ( password ) ).first ()
103111 if user is None :
104112 record_login_fail (username )
105113 raise AppApiException (500 , _ ('The username or password is incorrect' ))
0 commit comments