Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify method returns empty string on failure. Causes errors in combination with "use strict" #8

Open
Simerax opened this issue Jul 15, 2018 · 1 comment

Comments

@Simerax
Copy link

Simerax commented Jul 15, 2018

The Verify Function returns an empty string in case that "post_form" fails.
In combination with use strict; this causes an error "Can't use string as HASH ref"

Im not an active user of this module and don't know the quirks of it for this reason Im not creating a pull request

use strict;
# ...
my $response = param( 'g-recaptcha-response' );
my $result = $rc->verify('secret', $response);
if ($result->{success}) { # error right here
    # ...
}

Source:

sub verify {
    my ($self, $secret, $response, $remoteip) = @_;

    if (!defined $secret) {
        croak 'Secret key is required to verify reCAPTCHA';
    }

    if (!defined $response) {
        croak 'Response from user is required to verify reCAPTCHA';
    }

    my $params = {
        secret    => $secret,
        response  => $response,
    };

    $params->{remoteip} = $remoteip if defined $remoteip;

    my $res = $self->{ua}->post_form(
        $self->{verify_api},
        $params
    );


    if ($res->{success}) {
        my $content = decode_json $res->{content};
        if ($content->{success}){
            return { success => 1 };
        } else {
            return { success => 0, error_codes => $content->{'error-codes'} };
        }
    }
    # SHOULD HAVE AN ELSE HERE WHICH RETURNS THE APPROPRIATE ERROR HASH
}
@PitWenkin
Copy link

Duplicate of  #4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants