Ticket #1115: recaptcha_fix.diff

File recaptcha_fix.diff, 1.9 KB (added by teleyinex, 13 years ago)

reCAPTCHA patch for account creation

  • create_account_form.php

     
    2020require_once('../inc/util.inc');
    2121require_once('../inc/countries.inc');
    2222require_once('../inc/translation.inc');
     23require_once('../inc/recaptchalib.php');
    2324
    2425check_get_args(array("next_url", "teamid"));
    2526
     
    111112    tra("Postal or ZIP Code")."<br><span class=\"description\">".tra("Optional")."</span>",
    112113    "<input type=\"text\" name=\"postal_code\" size=\"20\">"
    113114);
     115
     116// Check if we need reCaptcha for making more safe the creation of accounts
     117$publickey = parse_config($config, "<recaptcha_public_key>");
     118
     119if ($publickey) {
     120
     121        row2(
     122            tra("Please enter the words shown in the image"),
     123            recaptcha_get_html($publickey)
     124        );
     125}
     126
    114127row2("",
    115128    "<input type=\"submit\" value=\"".tra("Create account")."\">"
    116129);
  • create_account_action.php

     
    2020include_once("../inc/util.inc");
    2121include_once("../inc/email.inc");
    2222include_once("../inc/user.inc");
     23include_once("../inc/recaptchalib.php");
    2324
    2425function show_error($str) {
    2526    page_head("Can't create account");
     
    4142    exit();
    4243}
    4344
     45$privatekey = parse_config($config, "<recaptcha_private_key>");
     46  if ($privatekey) {
     47      $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"],
     48          $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]
     49      );
     50      if (!$resp->is_valid) {
     51          echo "" . tra("Your reCAPTCHA response was not correct. Please try again."). "";
     52          return;
     53      }
     54  }
     55
    4456// see whether the new account should be pre-enrolled in a team,
    4557// and initialized with its founder's project prefs
    4658//