Commit c0b279c010da455e4d38580c0302a25ef50466f1
1 parent
92f91c62
Exists in
master
and in
6 other branches
Fix private_token usage
Showing
1 changed file
with
18 additions
and
20 deletions
Show diff stats
js/main.js
| @@ -20,14 +20,10 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -20,14 +20,10 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 20 | var participa = true; | 20 | var participa = true; |
| 21 | if(participa){ | 21 | if(participa){ |
| 22 | var host = 'http://www.participa.br'; | 22 | var host = 'http://www.participa.br'; |
| 23 | - var private_token = '375bee7e17d0021af7160ce664874618'; //participa | ||
| 24 | var proposal_discussion = '92856'; //participa | 23 | var proposal_discussion = '92856'; //participa |
| 25 | }else{ | 24 | }else{ |
| 26 | var host = 'http://noosfero.com:3000'; | 25 | var host = 'http://noosfero.com:3000'; |
| 27 | - //var private_token = 'bd8996155f5ea4354e42fee50b4b6891'; //casa | ||
| 28 | - var private_token = 'aae32bf5031e895b00a20a529d763b31'; //local serpro | ||
| 29 | var proposal_discussion = '632'; //local serpro | 26 | var proposal_discussion = '632'; //local serpro |
| 30 | - //var proposal_discussion = '401'; //casa | ||
| 31 | } | 27 | } |
| 32 | 28 | ||
| 33 | var BARRA_ADDED = false; | 29 | var BARRA_ADDED = false; |
| @@ -36,7 +32,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -36,7 +32,9 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 36 | Main = (function(){ | 32 | Main = (function(){ |
| 37 | 33 | ||
| 38 | return { | 34 | return { |
| 39 | - loadRandomProposal: function (topic_id, private_token) { | 35 | + private_token: '375bee7e17d0021af7160ce664874618', |
| 36 | + loadRandomProposal: function (topic_id) { | ||
| 37 | + var private_token = Main.private_token; | ||
| 40 | var $noProposals = $('.no-proposals'); | 38 | var $noProposals = $('.no-proposals'); |
| 41 | var $loading = $('.loading'); | 39 | var $loading = $('.loading'); |
| 42 | var $randomProposal = $('.random-proposal'); | 40 | var $randomProposal = $('.random-proposal'); |
| @@ -48,7 +46,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -48,7 +46,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 48 | $loading.show(); | 46 | $loading.show(); |
| 49 | $randomProposal.html(''); | 47 | $randomProposal.html(''); |
| 50 | 48 | ||
| 51 | - var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; | 49 | + var url = host + '/api/v1/articles/' + topic_id + '/children' + '?private_token=' + Main.private_token + '&limit=1&order=random()&_='+new Date().getTime()+'&fields=id,name,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal'; |
| 52 | $.getJSON(url).done(function( data ) { | 50 | $.getJSON(url).done(function( data ) { |
| 53 | $loading.hide(); | 51 | $loading.hide(); |
| 54 | 52 | ||
| @@ -63,7 +61,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -63,7 +61,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 63 | $randomProposal.html(supportProposalTemplate(article)); | 61 | $randomProposal.html(supportProposalTemplate(article)); |
| 64 | $body.off('click', '.vote-actions .skip'); | 62 | $body.off('click', '.vote-actions .skip'); |
| 65 | $body.on('click', '.vote-actions .skip', function(e) { | 63 | $body.on('click', '.vote-actions .skip', function(e) { |
| 66 | - contextMain.loadRandomProposal(topic_id, private_token); | 64 | + contextMain.loadRandomProposal(topic_id); |
| 67 | e.preventDefault(); | 65 | e.preventDefault(); |
| 68 | }); | 66 | }); |
| 69 | $body.off('click', '.vote-actions .like'); | 67 | $body.off('click', '.vote-actions .like'); |
| @@ -71,7 +69,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -71,7 +69,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 71 | //Helps to prevent more than one vote per proposal | 69 | //Helps to prevent more than one vote per proposal |
| 72 | if(ProposalApp.hasProposalbeenVoted(article.id)){ | 70 | if(ProposalApp.hasProposalbeenVoted(article.id)){ |
| 73 | console.log("Proposta " + article.id + " já havia sido votada"); | 71 | console.log("Proposta " + article.id + " já havia sido votada"); |
| 74 | - contextMain.loadRandomProposal(topic_id, private_token); | 72 | + contextMain.loadRandomProposal(topic_id); |
| 75 | e.preventDefault(); | 73 | e.preventDefault(); |
| 76 | return; | 74 | return; |
| 77 | } | 75 | } |
| @@ -87,11 +85,11 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -87,11 +85,11 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 87 | url: host + '/api/v1/articles/' + article.id + '/vote', | 85 | url: host + '/api/v1/articles/' + article.id + '/vote', |
| 88 | data: { | 86 | data: { |
| 89 | value: $(this).data('vote-value'), | 87 | value: $(this).data('vote-value'), |
| 90 | - private_token: private_token | 88 | + private_token: Main.private_token |
| 91 | } | 89 | } |
| 92 | }).done(function( /*data*/ ) { | 90 | }).done(function( /*data*/ ) { |
| 93 | ProposalApp.addVotedProposal(article.id); | 91 | ProposalApp.addVotedProposal(article.id); |
| 94 | - contextMain.loadRandomProposal(topic_id, private_token); | 92 | + contextMain.loadRandomProposal(topic_id); |
| 95 | }); | 93 | }); |
| 96 | e.preventDefault(); | 94 | e.preventDefault(); |
| 97 | }); | 95 | }); |
| @@ -119,7 +117,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -119,7 +117,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 119 | $resultsContainer.find('.results-content').hide(); | 117 | $resultsContainer.find('.results-content').hide(); |
| 120 | 118 | ||
| 121 | var per_page = 10; | 119 | var per_page = 10; |
| 122 | - var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?private_token=' + private_token + '&per_page='+per_page+'&page='+page; | 120 | + var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking' + '?private_token=' + Main.private_token + '&per_page='+per_page+'&page='+page; |
| 123 | $.getJSON(url).done(function( data, stats, xhr ) { | 121 | $.getJSON(url).done(function( data, stats, xhr ) { |
| 124 | data.pagination = { | 122 | data.pagination = { |
| 125 | total: parseInt(xhr.getResponseHeader('Total')), | 123 | total: parseInt(xhr.getResponseHeader('Total')), |
| @@ -163,12 +161,12 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -163,12 +161,12 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 163 | 161 | ||
| 164 | if(logged_in) { | 162 | if(logged_in) { |
| 165 | if(token){ | 163 | if(token){ |
| 166 | - private_token = token; | 164 | + Main.private_token = token; |
| 167 | } | 165 | } |
| 168 | loginButton.siblings('.require-login').show(); | 166 | loginButton.siblings('.require-login').show(); |
| 169 | loginButton.siblings('.require-login .message').show(); | 167 | loginButton.siblings('.require-login .message').show(); |
| 170 | loginButton.siblings('.login-container').hide(); | 168 | loginButton.siblings('.login-container').hide(); |
| 171 | - $.cookie('_dialoga_session', private_token); | 169 | + $.cookie('_dialoga_session', Main.private_token); |
| 172 | } else { | 170 | } else { |
| 173 | loginButton.siblings('.require-login').hide(); | 171 | loginButton.siblings('.require-login').hide(); |
| 174 | loginButton.siblings('.login-container').show(); | 172 | loginButton.siblings('.login-container').show(); |
| @@ -225,7 +223,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -225,7 +223,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 225 | $proposal.find('.calendar').slick(); | 223 | $proposal.find('.calendar').slick(); |
| 226 | 224 | ||
| 227 | var topic_id = proposal_id.split('-').pop(); | 225 | var topic_id = proposal_id.split('-').pop(); |
| 228 | - this.loadRandomProposal(topic_id, private_token); | 226 | + this.loadRandomProposal(topic_id); |
| 229 | }, | 227 | }, |
| 230 | display_proposal_detail: function(proposal_id){ | 228 | display_proposal_detail: function(proposal_id){ |
| 231 | $('#proposal-categories').hide(); | 229 | $('#proposal-categories').hide(); |
| @@ -243,7 +241,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -243,7 +241,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 243 | $proposal.find('.body').show(); | 241 | $proposal.find('.body').show(); |
| 244 | $proposal.show(); | 242 | $proposal.show(); |
| 245 | 243 | ||
| 246 | - var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; | 244 | + var url = host + '/api/v1/articles/' + proposal_id + '?private_token=' + Main.private_token + '&fields=id,body&content_type=ProposalsDiscussionPlugin::Topic'; |
| 247 | $.getJSON(url).done(function( data ) { | 245 | $.getJSON(url).done(function( data ) { |
| 248 | $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); | 246 | $('#proposal-item-' + proposal_id + ' .body-content').replaceWith(data.article.body); |
| 249 | }) | 247 | }) |
| @@ -442,12 +440,12 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -442,12 +440,12 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 442 | })(); | 440 | })(); |
| 443 | 441 | ||
| 444 | // Load data from localhost when it is dev env. | 442 | // Load data from localhost when it is dev env. |
| 445 | - var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + private_token + '&fields=id,children,categories,abstract,title,image,url,setting,position'; | 443 | + var noosferoAPI = host + '/api/v1/articles/' + proposal_discussion + '?private_token=' + Main.private_token + '&fields=id,children,categories,abstract,title,image,url,setting,position'; |
| 446 | 444 | ||
| 447 | $.getJSON(noosferoAPI) | 445 | $.getJSON(noosferoAPI) |
| 448 | .done(function( data ) { | 446 | .done(function( data ) { |
| 449 | data.host = host; | 447 | data.host = host; |
| 450 | - data.private_token = private_token; | 448 | + data.private_token = Main.private_token; |
| 451 | resultsPlaceholder.innerHTML = template(data); | 449 | resultsPlaceholder.innerHTML = template(data); |
| 452 | $('.login-container').html(loginTemplate()); | 450 | $('.login-container').html(loginTemplate()); |
| 453 | $('.countdown').maxlength({text: '%left caracteres restantes'}); | 451 | $('.countdown').maxlength({text: '%left caracteres restantes'}); |
| @@ -590,7 +588,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -590,7 +588,7 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 590 | $.ajax({ | 588 | $.ajax({ |
| 591 | type: 'post', | 589 | type: 'post', |
| 592 | url: host + $form.attr('action'), | 590 | url: host + $form.attr('action'), |
| 593 | - data: $('#'+this.id).serialize() + '&private_token=' + private_token + '&fields=id&article[name]=article_' + Main.guid() | 591 | + data: $('#'+this.id).serialize() + '&private_token=' + Main.private_token + '&fields=id&article[name]=article_' + Main.guid() |
| 594 | }) | 592 | }) |
| 595 | .done(function( /*data*/ ) { | 593 | .done(function( /*data*/ ) { |
| 596 | form.reset(); | 594 | form.reset(); |
| @@ -619,14 +617,14 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | @@ -619,14 +617,14 @@ define(['handlebars', 'fastclick', 'handlebars_helpers'], function(Handlebars, F | ||
| 619 | 617 | ||
| 620 | 618 | ||
| 621 | $(document).ready(function($) { | 619 | $(document).ready(function($) { |
| 622 | - | 620 | + |
| 623 | FastClick.attach(document.body); | 621 | FastClick.attach(document.body); |
| 624 | 622 | ||
| 625 | if($.cookie('_dialoga_session')) { | 623 | if($.cookie('_dialoga_session')) { |
| 626 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); | 624 | var url = host + '/api/v1/users/me?private_token=' + $.cookie('_dialoga_session'); |
| 627 | $.getJSON(url).done(function( /*data*/ ) { | 625 | $.getJSON(url).done(function( /*data*/ ) { |
| 628 | logged_in = true; | 626 | logged_in = true; |
| 629 | - private_token = $.cookie('_dialoga_session'); | 627 | + Main.private_token = $.cookie('_dialoga_session'); |
| 630 | }); | 628 | }); |
| 631 | } | 629 | } |
| 632 | 630 |