@@ -121,15 +121,17 @@ def user_login(request):
121121 print (_ ("Request POST: %(post)s" ) % {"post" : str (request .POST )})
122122 if device .verify_token (request .POST .get ("totp_code" , "" )):
123123 print (_ ("TOTP code is correct" ))
124- login (request , request .session ["user" ])
124+ user = get_user_model ().objects .get (id = request .session ["pending_user_id" ])
125+ login (request , user )
125126 if request .GET .get ("next" , "" ) != "" :
126127 return HttpResponseRedirect (request .GET ['next' ])
127128 else :
128129 return redirect ("index" )
129130 else :
130131 print (_ ("TOTP code is not correct: %(code)s" ) % {"code" : request .POST .get ("totp_code" , "" )})
132+ user = get_user_model ().objects .get (id = request .session ["pending_user_id" ])
131133 # return lac.templates.message(request, "Der TOTP-Code ist nicht korrekt! Versuchen Sie es erneut.", "login")
132- return get_totp_challenge_site (request , request . session [ " user" ] , _ ("Error: The TOTP code is not correct! Please try again." ))
134+ return get_totp_challenge_site (request , user , _ ("Error: The TOTP code is not correct! Please try again." ))
133135 print ("!127" )
134136 username = request .POST .get ('username' , '' )
135137 if username == "" :
@@ -211,7 +213,7 @@ def get_totp_challenge_site(request, user, message=""):
211213 set_value_in_cache (f"totp_challenge_{ request .session .session_key } " , datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" ), expiration_seconds = 300 )
212214 print (f"totp_challenge_{ request .session .session_key } " )
213215 print (get_value_from_cache (f"totp_challenge_{ request .session .session_key } " ))
214- request .session ["user " ] = user
216+ request .session ["pending_user_id " ] = user . id
215217 form = TOTPChallengeForm ()
216218 # Populate choice field with all totp devices of the user
217219 form .fields ["totp_device" ].choices = [(device .id , device .name ) for device in user .totpdevice_set .all ()]
0 commit comments