Jump to content

Recaptcha problem


allenchow

Recommended Posts

Hello,

I didn't expect someone use 2 recaptcha in the same time.

Fixed. You will get with new build. For now you can change uniReCAPTCHA.pas file with this.

 

unit UniReCAPTCHA;

interface

uses
  SysUtils, Classes, Controls, Forms, uniGUIBaseClasses, uniGUIClasses,
  uniPanel, uniHTMLFrame, uniGUITypes, uIdHTTP, uniGUIApplication;

type
  TUniReCAPTCHA = class(TUniCustomHTMLFrame)
  private
    FSiteKey: string;
    FVerified: boolean;
    FOnVerified: TNotifyEvent;
    FSecretKey: String;
    procedure SetSiteKey(const Value: string);
    procedure SetSecretKey(const Value: String);
    { Private declarations }
  protected
    procedure LoadCompleted; override;
    procedure JSEventHandler(AEventName: string; AParams: TUniStrings);override;
    procedure BeforeLoadCompleted; override;
  public
    constructor Create(AOwner:TComponent); override;
    destructor Destroy; override;
    { Public declarations }
  published
    property SiteKey:string read FSiteKey write SetSiteKey;
    property SecretKey: String read FSecretKey write SetSecretKey;
    property Verified : boolean read FVerified;
    property OnVerified :TNotifyEvent read FOnVerified write FOnVerified;
    procedure Reset;
    { Published declarations }
  end;

implementation


{ TUniReCAPTCHA }

procedure TUniReCAPTCHA.BeforeLoadCompleted;
var
 sWidth:string;
begin
  inherited;

  if Trim(FSiteKey)='' then
   begin
     raise Exception.Create('UniReCAPTCHA : Please Set SiteKey'+ #13#10+' To Get SiteKey Please Visit : https://www.google.com/recaptcha/admin');
     Exit;
   end;

  if Trim(FSecretKey)='' then
   begin
     raise Exception.Create('UniReCAPTCHA : Please Set SecretKey'+ #13#10+' To Get SecretKey Please Visit : https://www.google.com/recaptcha/admin');
     Exit;
   end;

  JSCode(JSName+'OnCallBack = function() {ajaxRequest('+JSName+', "OnCallBack", {response: grecaptcha.getResponse()}) };');
  sWidth:=StringReplace(FormatFloat('0.00',Width/302),',','.',[rfReplaceAll]);
  Height:=Trunc(76*Width/302);
  StaticHTML:=True;
  HTML.Text:='<div id="' + JSName + '_recaptcha" class="g-recaptcha" data-sitekey="'+FSiteKey+'" data-callback="'+JSName+'OnCallBack" style="transform:scale('+sWidth+');transform-origin:0 0"	></div>';
end;

constructor TUniReCAPTCHA.Create(AOwner: TComponent);
begin
  inherited;
  Width:=302;
  Height:=76;
end;

destructor TUniReCAPTCHA.Destroy;
begin

  inherited;
end;

procedure TUniReCAPTCHA.JSEventHandler(AEventName: string;
  AParams: TUniStrings);
var
  idHttp1: TIdHTTP;
  response: String;
begin
  inherited;
  if AEventName='OnCallBack' then
    begin
      idHttp1:=TIdHTTP.Create(Self);
      try
//        idHttp1.IOHandler := TIdSSLIOHandlerSocketOpenSSL.Create(idHttp1);
//        idHttp1.HandleRedirects := True;

        response := idHttp1.Get('https://www.google.com/recaptcha/api/siteverify?secret='+FSecretKey+'&response='+AParams['response'].AsString);
        if Pos('"success": true', response)>0 then
        begin
          FVerified:=True;
          if Assigned(OnVerified) then OnVerified(Self);
        end;
      finally
        idHttp1.Free;
      end;
    end;
end;

procedure TUniReCAPTCHA.LoadCompleted;
begin
  inherited;
  JSCallGlobal('setTimeout', [JSFunction('','recaptcha = document.getElementById("' + JSName + '_recaptcha"); if (recaptcha) {grecaptcha.render(recaptcha);}'),100]);
end;

procedure TUniReCAPTCHA.Reset;
begin
  FVerified:=False;
  JSCallGlobal('grecaptcha.reset',[]);
end;

procedure TUniReCAPTCHA.SetSecretKey(const Value: String);
begin
  FSecretKey := Value;
end;

procedure TUniReCAPTCHA.SetSiteKey(const Value: string);
begin
  FSiteKey := Value;
end;

initialization
  UniAddJSLibrary('https://www.google.com/recaptcha/api.js?render=explicit', True, [upoPlatformBoth]);

end.

 

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
4 hours ago, pro_imaj said:

 

Hi, never encountered this problem when I change the server is the solution I'm having this problem?

Thank you.

Error Code


Could not load SSL library.

Thanks.

The problem; improved when  installed 32 bit dll files while Windows was 64 bit.

Good work.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...