Добавляем reCAPTCHA на потльзовательскую регистрацию в OTRS

  1. Регистрируемся на https://www.google.com/recaptcha/admin/create
  2. Ставим reCAPTCHA одним из вариантов
    • cpan Captcha::reCAPTCHA
    • pkg_add -r p5-Captcha-reCAPTCHA
    • make install 😉
  3. Добавляем в CustomerLogin.dtl

    #            <tr>
    #              <td>$Text{“CustomerID”}: </td>
    #              <td> <input type=”text” name=”CustomerID” value=”$QData{“UserCustomerID”}” size=”25″ maxlength=”50″/></td>

    #            </tr>
    # begin recaptcha
    <tr>
    <td colspan=2>$Data{“reCAPTCHA”}</td>
    </tr>
    #end recaptcha
    </table>
    <input type=”submit” value=”$Text{“Create”}”/>

  4. Редактируем Kernel/Output/HTML/Layout.pm

    use Captcha::reCAPTCHA;

    После линии 3897 добавляем

    if (
    $Self->{ConfigObject}->Get(‘CustomerPanelCreateAccount’)
    && $Self->{ConfigObject}->Get(‘Customer::AuthModule’) eq
    ‘Kernel::System::CustomerAuth::DB’
    )
    {
    #begin recaptcha
    my $rc = Captcha::reCAPTCHA->new;
    my $rccustom = “<script type= \”text/javascript\”>\n
    var RecaptchaOptions = {\n
    lang : ‘ru’,
    };\n
    </script>\n”;
    $Param{reCAPTCHA} = $rccustom . $rc->get_html(“your_recaptcha_public_key”);
    #end recaptcha
    $Self->Block(
    Name => ‘CreateAccount’,
    Data => \%Param,
    );
    }

  5. Правим Kernel/System/Web/InterfaceCustomer.pm

    use Captcha::reCAPTCHA;

    После линии 569 добавляем

    # check needed params
    if ( !$GetParams{UserCustomerID} ) {
    $GetParams{UserCustomerID} = $GetParams{UserEmail};
    }
    if ( !$GetParams{UserLogin} ) {
    $GetParams{UserLogin} = $GetParams{UserEmail};
    }
    # check reCAPTCHA
    my $rc = Captcha::reCAPTCHA->new;
    my $challenge = $Self->{ParamObject}->GetParam( Param => ‘recaptcha_challenge_field’ )  || ”;
    my $response = $Self->{ParamObject}->GetParam( Param => ‘recaptcha_response_field’ )  || ”;
    my $result = $rc->check_answer(“your_private_recaptcha_key”, $ENV{‘REMOTE_ADDR’},
    $challenge, $response
    );
    if ( !$result->{is_valid} ) {
    my $Output = $Self->{LayoutObject}->CustomerHeader( Area => ‘Core’, Title => ‘Error’ );
    $Output .= $Self->{LayoutObject}->CustomerWarning(
    Message => ‘reCAPTCHA entry failed.’,
    Comment => ‘Please press Back and try again.’
    );
    $Output .= $Self->{LayoutObject}->CustomerFooter();
    $Self->{LayoutObject}->Print( Output => \$Output );
    exit 0;
    }
    #end recaptcha

Вуаля.

Comments are closed.