2014-03-25 2 views
0

메테오와 채팅 앱을 만들고 있는데 스팸이 문제가 될 것이라고 생각합니다. 너무 빨리 댓글을 달면 (5 초에 3 번 이상) 대문자가 나타나는 Captcha를 통합하려고합니다. 내가 아래 자바 스크립트 코드가 있지만 어떻게 해야할지 모르겠다. Captcha를 화면의 어딘가에 팝업시킬 수 있습니까? 그렇다면 누구든지이 작업을 수행하는 방법을 알고 있습니까?사용자의 의견이 너무 빠른 경우 보안 문자 팝업?

자바 스크립트 :

// render all of our messages in the ui 
Template.chatBox.helpers({ 
    "messages": function() { 
    return chatCollection.find(); 
    } 
}); 

// get the value for handlerbar helper user 
Template.chatMessage.helpers({ 
    "user": function() { 
    if(this.userId == 'me') { 
     return this.userId; 
    } else if(this.userId) { 
     getUsername(this.userId); 
     return Session.get('user-' + this.userId); 
    } else { 
     return 'anonymous-' + this.subscriptionId; 
    } 
    } 
}); 

// when Send Chat clicked at the message to the collection 
Template.chatBox.events({ 
    "click #send": function() { 
     if (Meteor.user() == null) { 
      alert("You must login to post"); 
      return; 
     } 
     $('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast"); 
     var message = $('#chat-message').val(); 
     chatCollection.insert({ 
      userId: 'me', 
      message: message 
     }); 
     $('#chat-message').val(''); 

     //add the message to the stream 
     chatStream.emit('chat', message); 
    }, 

    "keypress #chat-message": function(e) { 
     if (Meteor.user() == null) { 
      alert("You must login to post"); 
      return; 
     } 
     if (e.which == 13) { 
      $('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast"); 
      console.log("you pressed enter"); 
      e.preventDefault(); 
      //repeat function from #send click event here 
      var message = $('#chat-message').val(); 
      chatCollection.insert({ 
       userId: 'me', 
       message: message 
      }); 
      $('#chat-message').val(''); 

    //add the message to the stream 
    chatStream.emit('chat', message); 
    } 
    } 
}); 

chatStream.on('chat', function(message) { 
    chatCollection.insert({ 
    userId: this.userId, 
    subscriptionId: this.subscriptionId, 
    message: message 
    }); 
}); 
+0

Jquery를 사용하고 있습니까? –

+0

나는 유성과 할 수 있다고 생각하지 않는다. – 5AMWE5T

+0

시도해 보셨습니까? –

답변

1

내가 코드에 몇 가지 코드를 추가 한 다음 채팅 응용 프로그램 부분에 대한 코드입니다. 나는 Meteor를 사용하지 않으므로이 코드가 Meteor에서 작동하는지 여부를 알지 못합니다. 그러나 여기 직유법 프로젝트 here

Template.chatBox.events({ 
    "click #send": function() { 
     if (Meteor.user() == null) { 
      alert("You must login to post"); 
      return; 
     } 

     //Validation 
     var bot =Check_bots(); 

     if(bot==false) 
     { 
      $('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast"); 
      var message = $('#chat-message').val(); 
      chatCollection.insert({ 
       userId: 'me', 
       message: message 
      }); 
      $('#chat-message').val(''); 

      //add the message to the stream 
      chatStream.emit('chat', message); 
     } 
     else 
     { 
      // Do whatever you want when a Bot detected 
     } 
    }, 

    "keypress #chat-message": function(e) { 
     if (Meteor.user() == null) { 
      alert("You must login to post"); 
      return; 
     } 
     if (e.which == 13) { 
      $('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast"); 
      console.log("you pressed enter"); 
      e.preventDefault(); 
      //repeat function from #send click event here 
      var message = $('#chat-message').val(); 
      chatCollection.insert({ 
       userId: 'me', 
       message: message 
      }); 
      $('#chat-message').val(''); 

    //add the message to the stream 
    chatStream.emit('chat', message); 
    } 
    } 
}); 

를 작성하여이를 테스트 유효성 검사 코드

<script type="text/javascript"> 
var lastintime=0; 
var defference=0; 
var msg_count=0; 

function Check_bots() 
{ 
    var seconds = new Date().getTime()/1000; 
    seconds=parseInt(seconds); 

    if(lastintime < seconds) 
    { 
     defference = seconds -lastintime; 
     lastintime=seconds; 

     if(defference<=5 && msg_count>=3) 
     { 
      return true; 
     } 
     else 
     { 
      return false; 
     } 
    } 
} 

</script> 
+0

자바 스크립트 코드를 넣으십시오 –

+0

고마워요! 코드를 사용하여 작동하도록했습니다. 이것은 많은 도움이되었습니다! – 5AMWE5T

2

이 좋은 생각 같은 소리입니다,하지만 '조건 보안 문자'를 사용하여 몇 가지 문제가있다. 하나는 JavaScript가 쿠키 및 localStorage 이외의 페이지를 다시로드 할 수있는 방법이 없다는 것입니다. 따라서 쿠키를 간단히 새로 고침하고 지우면 쿠키가 삭제됩니다. 서버에서 처리하는 방법은 말할 것도없고 유효한 captcha 입력이 필요한지 아닌지 확실하지 않습니다.

그런 경고가 나오면 '타이머'역할을하는 전역 변수를 설정하고 경과를 추적 할 수 있습니다. 그래서와 마지막 블록 교체 :

chatStream.on('chat', function(message) { 
    //do we already have a timer? 
    if(typeof window.chatTimer == 'undefined'){ 
     //no, so start one right now 
     window.chatTimer = new Date().getTime(); 
    }else{ 
     //we already have a timer. Is it 5 seconds old? 
     var now = new Date().getTime(); 
     if(now - window.chatTimer < 5000) { 
     alert('Not so fast, tiger.'); 
     return false; 
     }else{ 
     chatCollection.insert({ 
     userId: this.userId, 
     subscriptionId: this.subscriptionId, 
     message: message 
     }); 
    } 

이 예는 reCaptcha를 사용을 뺀 정의 물건 당신이 전달할 것입니다 아마이 최근 변경

,하지만 스팸봇은 자바 스크립트를 실행하지 마십시오.. 이들은 링크를 따라 가서 formtextbox 요소를 찾은 다음 검색 엔진의 독점 요소를 차단하려는 모든 JavaScript를 우회하여 양식의 작업 속성에 대한 POST 요청을 작성합니다.

사실 captcha의 대안 중 하나는 단순히 서버가 기다리고있는 애매한 ID/이름을 가진 JavaScript로 숨겨진 입력을 동적으로 생성하는 것입니다. 스팸봇은이 자바 스크립트를 실행하지 않으므로 확인란이 선택되지 않으므로 봇은 이유를 모른 채 거부됩니다. Here's more on that.

+0

자세히 설명해 주셔서 감사합니다. 귀하의 게시물을 읽고 나면 이제는 스팸 봇이 문제가 아니라 다른 사이트를 광고하려고하는 실제 사용자라고 생각합니다. captcha 대신 어쩌면 속도가 느려지라는 팝업이 나올 수도 있습니다. 이 작업을 수행하는 방법을 알고 있습니까? – 5AMWE5T

+0

대신 경고를 사용하도록 코드를 편집했습니다. –