Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var $lg_username=$('#login_username').val();
- var $lg_password=$('#login_password').val();
- var $lg_lemb=$('#login_lemb').val();
- var $responseG = grecaptcha.getResponse();
- if($responseG.length == 0){
- msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), "error", "glyphicon-remove", "reCAPTCHA obrigatório!");
- } else {
- if ($lg_username == "" && $lg_password == "") {
- msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), "error", "glyphicon-remove", "Ambos os campos são obrigatórios!");
- } else {
- $.post( $("body").attr("data-url") + "/login", { email: $lg_username, senha: $lg_password, lembre: $lg_lemb, response: grecaptcha.getResponse() }).done(function( data ) {
- alert(data);
- data.split("|");
- msgChange($('#div-login-msg'), $('#icon-login-msg'), $('#text-login-msg'), data['0'], data['1'], data['2']);
- if(data['0']==success){
- setTimeout("window.location='"+ $("body").attr("data-url-full") +"'",2000);
- }
- });
- }
- }
- class GoogleRecaptcha
- {
- /* Google recaptcha API url */
- private $google_url = "https://www.google.com/recaptcha/api/siteverify";
- private $secret = 'minhachavescretaaqui';
- public function VerifyCaptcha($response)
- {
- $url = $this->google_url."?secret=".$this->secret.
- "&response=".$response;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($curl, CURLOPT_TIMEOUT, 15);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, TRUE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- $curlData = curl_exec($curl);
- curl_close($curl);
- $res = json_decode($curlData, TRUE);
- if($res['success'] == 'true')
- return TRUE;
- else
- return FALSE;
- }
- }
- if($_SERVER["REQUEST_METHOD"] == "POST")
- {
- $response = $_POST['response'];
- if(!empty($response))
- {
- $cap = new GoogleRecaptcha();
- $verified = $cap->VerifyCaptcha($response);
- if($verified) {
- echo "success|glyphicon-ok|Logando, aguarde...";
- } else {
- echo utf8_encode("error|glyphicon-remove|Usuário e ou senha inválidos!");
- }
- } else {
- echo utf8_encode("error|glyphicon-remove|reCAPTCHA inválido!");
- }
- } else {
- echo utf8_encode("error|glyphicon-remove|reCAPTCHA é obrigatório!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement