mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	altcha: More error-proofing around settings validation.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							f0f916f538
						
					
				
				
					commit
					8af90294d8
				
			@@ -403,6 +403,8 @@ class CaptchaRealmCreationForm(RealmCreationForm):
 | 
			
		||||
 | 
			
		||||
    def clean_captcha(self) -> str:
 | 
			
		||||
        payload = self.data.get("captcha", "")
 | 
			
		||||
        if not settings.USING_CAPTCHA or not settings.ALTCHA_HMAC_KEY:  # nocoverage
 | 
			
		||||
            raise forms.ValidationError(_("Challenges are not enabled."))
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            ok, err = verify_solution(payload, settings.ALTCHA_HMAC_KEY, check_expires=True)
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,9 @@ class AltchaPayload(BaseModel):
 | 
			
		||||
def get_challenge(
 | 
			
		||||
    request: HttpRequest,
 | 
			
		||||
) -> HttpResponseBase:
 | 
			
		||||
    if not settings.USING_CAPTCHA or not settings.ALTCHA_HMAC_KEY:  # nocoverage
 | 
			
		||||
        raise JsonableError(_("Challenges are not enabled."))
 | 
			
		||||
 | 
			
		||||
    now = timezone_now()
 | 
			
		||||
    expires = now + timedelta(minutes=1)
 | 
			
		||||
    try:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user