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