reCaptcha on CustomerLogin for Create Account (5.0.x)

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Sidhy
OTRS newbie
Posts: 1
Joined: 22 Oct 2016, 18:47
OTRS Version?: 5.0.x
Real Name: Jorrit

reCaptcha on CustomerLogin for Create Account (5.0.x)

Postby Sidhy » 22 Oct 2016, 19:51

Credits to crythias for his howto which can be found here: http://forums.otterhub.org/viewtopic.php?t=5941
I Copied and modified most of his howto to work with 5.0.x

Part 0: get a key set https://www.google.com/recaptcha/admin/create
Part 1: install reCAPTCHA

Code: Select all

cpan Captcha::reCAPTCHA

(if you're on Windows, you may have to use a different method to install)

Part 2: Copy Custom Files

Code: Select all

cd /opt/otrs
mkdir -p Kernel/Output/HTML/Templates/Standard 
cp ../Kernel/Output/HTML/Layout.pm Kernel/Output/HTML/Layout.pm
cp ../Kernel/Output/HTML/Templates/Standard/CustomerLogin.tt Kernel/Output/HTML/Templates/Standard/CustomerLogin.tt
mkdir -p Custom/Kernel/System/Web
cp ../Kernel/System/Web/InterfaceCustomer.pm Custom/Kernel/System/Web/InterfaceCustomer.pm Kernel/System/Web/InterfaceCustomer.pm Custom/Kernel/System/Web/InterfaceCustomer.pm


Part 3: Customize /opt/otrs/Kernel/Output/HTML/Layout.pm
in the top where the use section is, add

Code: Select all

use Captcha::reCAPTCHA;


next search for "# get create account output" and add the #begin recaptcha to#end recaptcha block to it like below

Code: Select all


        
# get create account output
        if (
            $ConfigObject->Get('CustomerPanelCreateAccount')
            && $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 : 'en',
};\n
</script>\n"
;
        $Param{reCAPTCHA} = $rccustom . $rc->get_html("        ****PUBLIC KEY****         "); #public key
        #end recaptcha
        
            $Self
->Block(
                Name => 'CreateAccountLink',
                Data => \%Param,
            );
            $Self->Block(
                Name => 'CreateAccount',
                Data => \%Param,
            );
 


Part 4: Customize /opt/otrs/Custom/Kernel/System/Web/InterfaceCustomer.pm
in the top where the use section is, add

Code: Select all

use Captcha::reCAPTCHA;


Search for "# check needed params" and add #check reCAPTCHA to #end recaptcha like below

Code: Select all

# 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 = $ParamObject->GetParam(Param => 'recaptcha_challenge_field') || '';
        my $response = $ParamObject->GetParam(Param => 'recaptcha_response_field') || '';
        my $result = $rc->check_answer("   ****PRIVATE KEY****   ", $ENV{'REMOTE_ADDR'}, # private key
           $challenge, $response
           
);
        if ( !$result->{is_valid} ) {
            my $Output = $LayoutObject->CustomerHeader(
                Area  => 'Core',
                Title => 'Error'
            );
            $Output .= $LayoutObject->CustomerWarning(
                Message => 'reCAPTCHA entry failed.',
                Comment => 'Please press Back and try again.'
            );
            $Output .= $LayoutObject->CustomerFooter();
            $LayoutObject->Print( Output => \$Output );
            exit 0;
        }
        #end recaptcha   
        

        
# get new password
        $GetParams{UserPassword} = $UserObject->GenerateRandomPassword();
 


Step 5: /opt/otrs/Custom/Kernel/Output/HTML/Templates/Standard/CustomerLogin.tt
Search for "[% RenderBlockStart("CreateAccount") %]"
Scroll a bit down around line 135 you should add the recaptcha block like below

Code: Select all

<div class="NewLine">
                        <label class="Mandatory" for="Email"><span class="Marker">*</span> [% Translate("Email") | html %]</label>
                        <input title="[% Translate("Your email address (this will become your username)") | html %]" name="Email" type="[% Env("EmailFieldType") | html %]" id="Email" maxlength="150" value="[% Data.UserEmail | html %]" class="W100pc Validate_Required Validate_Email"/>
                        <div id="EmailError" class="TooltipErrorMessage"><p>[% Translate("This field is required.") | html %]</p></div>
                    </div>
                    <!-- begin recaptcha -->
                    <div class="NewLine">
                        
                        
[% Data.reCAPTCHA %]
                        
                    
</div>
                    <!-- end recaptcha -->
                    <div class="NewLine">
                        <button id="CreateAccount" type="submit" value="[% Translate("Create") | html %]" disabled="disabled">[% Translate("Create") | html %]</button>
                    </div>
                    <div class="Clear"></div>
                </form>
            </div>
 


Step 6: Fix CSS For displaying our captcha
edit file: /opt/otrs/var/httpd/htdocs/skins/Customer/default/css/Core.Login.css

Search for "#Slider {" and change height from 260 to 400
and search for "#PreLogin {" and change height from 260 to 400
example below (I commented out the old lines just as example):

Code: Select all

/**
 * @subsection  Slider
 */
#Slider {
    margin-bottom: 34px;
    width: 642px;
    /* height: 260px; */
    height: 400px;
    overflow: hidden;
}

#Slider h2 {
    line-height: 22px;
}

#Login,
#Reset,
#Signup,
#PreLogin {
    width: 500px;
    /* height: 260px; */
    height: 400px;
    padding-left: 142px;
    position: relative;
}
 

SergeyKhalyu
OTRS newbie
Posts: 4
Joined: 28 Apr 2017, 11:13
OTRS Version?: 4 version

Re: reCaptcha on CustomerLogin for Create Account (5.0.x)

Postby SergeyKhalyu » 31 May 2017, 14:32

Hello. I have certain problem in the very beginning then I try to install reCAPTCHA. I have Centos 7, so I tryed 2 ways to install perl module. And thats what happen next.

Code: Select all

[b][root@otrs5cent7 home]# sudo yum install "perl(Captcha::reCAPTCHA)"[/b]
Loaded plugins: fastestmirror
base                                                                                                 | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                 |  26 kB  00:00:00
epel                                                                                                 | 4.3 kB  00:00:00
extras                                                                                               | 3.4 kB  00:00:00
pgdg94                                                                                               | 4.1 kB  00:00:00
updates                                                                                              | 3.4 kB  00:00:00
(1/3): epel/x86_64/updateinfo                                                                        | 805 kB  00:00:00
(2/3): pgdg94/7/x86_64/primary_db                                                                    | 162 kB  00:00:00
(3/3): epel/x86_64/primary_db                                                                        | 4.7 MB  00:00:05
Loading mirror speeds from cached hostfile
 * base: centos-mirror.rbc.ru
 * epel: mirror.yandex.ru
 * extras: centos-mirror.rbc.ru
 * updates: centos-mirror.rbc.ru
No package perl(Captcha::reCAPTCHA) available.
Error: Nothing to do
[b][root@otrs5cent7 home]# cpanspec Captcha::reCAPTCHA[/b]
%packager not defined in ~/.rpmmacros.  Please add or use --packager option.
OTRS 4 CentOS 7

zzz
OTRS expert
Posts: 72
Joined: 15 Dec 2016, 15:13
OTRS Version?: 5.0.x

Re: reCaptcha on CustomerLogin for Create Account (5.0.x)

Postby zzz » 31 May 2017, 14:53

Hello SergeyKhalyu,

use

Code: Select all

cpan Captcha::reCAPTCHA
as mentioned above

zzz
OTRS expert
Posts: 72
Joined: 15 Dec 2016, 15:13
OTRS Version?: 5.0.x

Re: reCaptcha on CustomerLogin for Create Account (5.0.x)

Postby zzz » 31 May 2017, 14:53

Hello SergeyKhalyu,

use

Code: Select all

cpan Captcha::reCAPTCHA
as mentioned above

SergeyKhalyu
OTRS newbie
Posts: 4
Joined: 28 Apr 2017, 11:13
OTRS Version?: 4 version

Re: reCaptcha on CustomerLogin for Create Account (5.0.x)

Postby SergeyKhalyu » 01 Jun 2017, 09:48

Thank you very much!
I don't understand why in "Part 2: Copy Custom Files" some commands don't work
For example

Code: Select all

[root@otrs5cent7 ~]# cp ../Kernel/Output/HTML/Layout.pm Kernel/Output/HTML/Layout.pm
cp: cannot stat ‘../Kernel/Output/HTML/Layout.pm’: No such file or directory


.. using with cd command to switch to previous directory. I dont understand how it works with cp
OTRS 4 CentOS 7


Return to “Howtos”

Who is online

Users browsing this forum: No registered users and 1 guest