Page 1 of 1

Super-Easy ReCaptcha 2.0

Posted: Sun Jan 08, 2017 4:04 am
by tj1010

Code: Select all

Procedure DrawReCaptcha(x,y,sitekey$)
  If Len(sitekey$)>0
    !try{
    !var rcptcha=document.createElement('div');
    !rcptcha.setAttribute('class','g-recaptcha');
    !rcptcha.setAttribute('data-sitekey',v_sitekey$);
    !rcptcha.setAttribute('style','position:fixed;z-index:9999999999999;top:'+v_y+';left:'+v_x+';');
    !document.body.appendChild(rcptcha);
    !var gscript=document.createElement('script');
    !gscript.setAttribute('type','text/javascript');
    !gscript.setAttribute('src','https://www.google.com/recaptcha/api.js');
    !gscript.setAttribute('async','');
    !gscript.setAttribute('defer','');
    !document.getElementsByTagName('head')[0].appendChild(gscript);
    !}catch(err){
    !}
  EndIf
EndProcedure

Procedure DeleteReCaptcha()
  !try{
  !document.body.removeChild(document.getElementByClass('g-recaptcha')[0]);
  !}catch(err){
  !}
EndProcedure

Procedure.s GetReCaptcha()
  Protected answ$=""
  !try{
  !v_answ=grecaptcha.getResponse();
  !}catch(err){
  !}
  ProcedureReturn answ$
EndProcedure

;demo
ExamineDesktops()
DrawReCaptcha((DesktopWidth(0)/2)-200,(DesktopHeight(0)/2)-200,"YOURSITEKEYHERE")
Repeat
  ;do stuff
Until Len(GetReCaptcha())>0
;send it to your server for verification with google api
NOTES:
  • I haven't tested it just going by up to date docs and my experience writing it. You check GetReCaptcha() string on your back-end using cURL or whatever with the private-key and google returns some JSON you check.
  • To use it in SB gadgets you calculate it's desktop x,y(not window-relative) and set this relative to it's x and y.
  • You can use it in mobile apps by removing domain check in Google control panel(when SB team actually fixes http on Android and IOS)

Re: Super-Easy ReCaptcha 2.0

Posted: Wed Feb 15, 2017 7:51 pm
by Peter
Browser wrote:ReferenceError: v_sitekey is not defined
change:

Code: Select all

    !rcptcha.setAttribute('data-sitekey',v_sitekey);
to:

Code: Select all

    !rcptcha.setAttribute('data-sitekey',v_sitekey$);
Greetings ... Peter

Re: Super-Easy ReCaptcha 2.0

Posted: Thu Feb 16, 2017 6:59 am
by Fred
Changed