mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-03 20:48:07 +00:00 
			
		
		
		
	- added hCaptcha based verification for chatwoot signups Co-authored-by: Sojan <sojan@pepalo.com>
		
			
				
	
	
		
			26 lines
		
	
	
		
			668 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			26 lines
		
	
	
		
			668 B
		
	
	
	
		
			Ruby
		
	
	
	
	
	
class ChatwootCaptcha
 | 
						|
  def initialize(client_response)
 | 
						|
    @client_response = client_response
 | 
						|
    @server_key = GlobalConfigService.load('HCAPTCHA_SERVER_KEY', '')
 | 
						|
  end
 | 
						|
 | 
						|
  def valid?
 | 
						|
    return true if @server_key.blank?
 | 
						|
    return false if @client_response.blank?
 | 
						|
 | 
						|
    validate_client_response?
 | 
						|
  end
 | 
						|
 | 
						|
  def validate_client_response?
 | 
						|
    response = HTTParty.post('https://hcaptcha.com/siteverify',
 | 
						|
                             body: {
 | 
						|
                               response: @client_response,
 | 
						|
                               secret: @server_key
 | 
						|
                             })
 | 
						|
 | 
						|
    return unless response.success?
 | 
						|
 | 
						|
    response.parsed_response['success']
 | 
						|
  end
 | 
						|
end
 |