Commit f85393afd35f943f1d68c4bf38e7387738fac141
1 parent
0a815e7d
Exists in
captcha
Add captcha
Showing
2 changed files
with
15 additions
and
4 deletions
Show diff stats
index.html
| @@ -71,7 +71,7 @@ | @@ -71,7 +71,7 @@ | ||
| 71 | } | 71 | } |
| 72 | loadCSSFiles(); | 72 | loadCSSFiles(); |
| 73 | </script> | 73 | </script> |
| 74 | - | 74 | + <script src='https://www.google.com/recaptcha/api.js?hl=pt-BR&render=explicit' async defer></script> |
| 75 | </head> | 75 | </head> |
| 76 | <body> | 76 | <body> |
| 77 | <div class="container"> | 77 | <div class="container"> |
| @@ -282,6 +282,7 @@ | @@ -282,6 +282,7 @@ | ||
| 282 | <div class="abstract"> | 282 | <div class="abstract"> |
| 283 | <p>{{stripTags (trimString abstract 200)}}</p> | 283 | <p>{{stripTags (trimString abstract 200)}}</p> |
| 284 | </div> | 284 | </div> |
| 285 | + <div class="captcha"></div> | ||
| 285 | <div class="vote-actions"> | 286 | <div class="vote-actions"> |
| 286 | <a href="#" class="like dislike" data-vote-value="-1"></a> | 287 | <a href="#" class="like dislike" data-vote-value="-1"></a> |
| 287 | <a href="#" class="like" data-vote-value="1"></a> | 288 | <a href="#" class="like" data-vote-value="1"></a> |
js/main.js
| @@ -59,6 +59,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -59,6 +59,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 59 | 59 | ||
| 60 | var article = data.articles[0]; | 60 | var article = data.articles[0]; |
| 61 | $randomProposal.html(supportProposalTemplate(article)); | 61 | $randomProposal.html(supportProposalTemplate(article)); |
| 62 | + | ||
| 63 | + captcha = Main.loadCaptcha($randomProposal.find('.captcha')[0]); | ||
| 64 | + | ||
| 62 | $body.off('click', '.vote-actions .skip'); | 65 | $body.off('click', '.vote-actions .skip'); |
| 63 | $body.on('click', '.vote-actions .skip', function(e) { | 66 | $body.on('click', '.vote-actions .skip', function(e) { |
| 64 | contextMain.loadRandomProposal(topic_id, private_token); | 67 | contextMain.loadRandomProposal(topic_id, private_token); |
| @@ -67,19 +70,22 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -67,19 +70,22 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 67 | $body.off('click', '.vote-actions .like'); | 70 | $body.off('click', '.vote-actions .like'); |
| 68 | $body.on('click', '.vote-actions .like', function(e) { | 71 | $body.on('click', '.vote-actions .like', function(e) { |
| 69 | //Helps to prevent more than one vote per proposal | 72 | //Helps to prevent more than one vote per proposal |
| 73 | + /* | ||
| 70 | if(ProposalApp.hasProposalbeenVoted(article.id)){ | 74 | if(ProposalApp.hasProposalbeenVoted(article.id)){ |
| 71 | console.log("Proposta " + article.id + " já havia sido votada"); | 75 | console.log("Proposta " + article.id + " já havia sido votada"); |
| 72 | contextMain.loadRandomProposal(topic_id, private_token); | 76 | contextMain.loadRandomProposal(topic_id, private_token); |
| 73 | e.preventDefault(); | 77 | e.preventDefault(); |
| 74 | return; | 78 | return; |
| 75 | } | 79 | } |
| 80 | + */ | ||
| 76 | $.ajax({ | 81 | $.ajax({ |
| 77 | type: 'post', | 82 | type: 'post', |
| 78 | url: host + '/api/v1/articles/' + article.id + '/vote', | 83 | url: host + '/api/v1/articles/' + article.id + '/vote', |
| 79 | data: { | 84 | data: { |
| 80 | value: $(this).data('vote-value'), | 85 | value: $(this).data('vote-value'), |
| 81 | - private_token: private_token | ||
| 82 | - } | 86 | + private_token: private_token, |
| 87 | + captchaResponse: grecaptcha.getResponse(captcha) | ||
| 88 | + }, | ||
| 83 | }).done(function( /*data*/ ) { | 89 | }).done(function( /*data*/ ) { |
| 84 | ProposalApp.addVotedProposal(article.id); | 90 | ProposalApp.addVotedProposal(article.id); |
| 85 | contextMain.loadRandomProposal(topic_id, private_token); | 91 | contextMain.loadRandomProposal(topic_id, private_token); |
| @@ -303,6 +309,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -303,6 +309,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 303 | 309 | ||
| 304 | BARRA_ADDED = true; | 310 | BARRA_ADDED = true; |
| 305 | }, | 311 | }, |
| 312 | + loadCaptcha: function(element) { | ||
| 313 | + return grecaptcha.render(element, {'sitekey': '6Lc4HAcTAAAAAGSpxDxbPiIX5lmIPSnPij-_mCYQ'}); | ||
| 314 | + }, | ||
| 306 | updateHash: function(hash){ | 315 | updateHash: function(hash){ |
| 307 | var id = hash.replace(/^.*#/, ''); | 316 | var id = hash.replace(/^.*#/, ''); |
| 308 | var elem = document.getElementById(id); | 317 | var elem = document.getElementById(id); |
| @@ -643,8 +652,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -643,8 +652,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 643 | 652 | ||
| 644 | $(document).on('click', '.new-user', function(e) { | 653 | $(document).on('click', '.new-user', function(e) { |
| 645 | var loginForm = $(this).parents('#login-form'); | 654 | var loginForm = $(this).parents('#login-form'); |
| 655 | + var signupForm = loginForm.siblings('#signup-form'); | ||
| 646 | loginForm.hide(); | 656 | loginForm.hide(); |
| 647 | - loginForm.siblings('#signup-form').show(); | 657 | + signupForm.show(); |
| 648 | loginForm.find('.message').hide(); | 658 | loginForm.find('.message').hide(); |
| 649 | e.preventDefault(); | 659 | e.preventDefault(); |
| 650 | }) | 660 | }) |