diff --git a/src/app/components/auth/auth.service.js b/src/app/components/auth/auth.service.js index aa42270..bcb3ffc 100644 --- a/src/app/components/auth/auth.service.js +++ b/src/app/components/auth/auth.service.js @@ -53,11 +53,7 @@ } function activate (code) { - var url = '/api/v1/activate'; - // var data = { - // private_token: API.token, - // activation_code: code - // }; + var url = PATH.host + '/api/v1/activate'; var encodedData = 'private_token=' + API.token; encodedData += '&activation_code=' + code; @@ -77,12 +73,7 @@ } function changePassword (code, newPassword, newPasswordConfirmation){ - var url = '/api/v1/new_password'; - // var data = { - // code: code, - // password: newPassword, - // password_confirmation: newPasswordConfirmation - // }; + var url = PATH.host + '/api/v1/new_password'; var encodedData = 'code=' + code; encodedData += '&password=' + newPassword; encodedData += '&password_confirmation=' + newPasswordConfirmation; @@ -103,7 +94,7 @@ } function forgotPassword (data){ - var url = 'http://hom.login.dialoga.gov.br/api/v1/forgot_password'; + var url = PATH.host + '/api/v1/forgot_password'; var encodedData = ([ 'value=' + data.login, 'captcha_text=' + data.captcha_text, @@ -129,8 +120,7 @@ } function login (credentials) { - var hostProd = 'http://login.dialoga.gov.br'; - var url = hostProd + '/api/v1/login'; + var url = PATH.host + '/api/v1/login'; var encodedData = 'login=' + credentials.username + '&password=' + credentials.password; return $http @@ -149,6 +139,13 @@ }); } + function loginCaptcha (data) { + var url = PATH.host + '/api/v1/login-captcha'; + var encodedData = angular.element.param(data); + + return $http.post(url, encodedData); + } + function logout () { Session.destroy(); @@ -190,6 +187,7 @@ changePassword: changePassword, forgotPassword: forgotPassword, login: login, + loginCaptcha: loginCaptcha, logout: logout, isAuthenticated: isAuthenticated, isAuthorized: isAuthorized diff --git a/src/app/components/proposal-box/proposal-box.directive.js b/src/app/components/proposal-box/proposal-box.directive.js index 704e639..8e6e676 100644 --- a/src/app/components/proposal-box/proposal-box.directive.js +++ b/src/app/components/proposal-box/proposal-box.directive.js @@ -9,15 +9,19 @@ function proposalBox() { /** @ngInject */ - function ProposalBoxController($scope, $rootScope, $state, VOTE_STATUS, VOTE_OPTIONS, $log) { + function ProposalBoxController($scope, $rootScope, $state, $timeout, $interval, $window, VOTE_STATUS, VOTE_OPTIONS, AuthService, $log) { $log.debug('ProposalBoxController'); var vm = this; vm.$scope = $scope; vm.$rootScope = $rootScope; vm.$state = $state; + vm.$timeout = $timeout; + vm.$interval = $interval; + vm.$window = $window; vm.VOTE_STATUS = VOTE_STATUS; vm.VOTE_OPTIONS = VOTE_OPTIONS; + vm.AuthService = AuthService; vm.$log = $log; vm.init(); @@ -28,11 +32,11 @@ var vm = this; - vm.canVote = vm.canVote || false; + vm.showVote = vm.showVote || false; vm.focus = vm.focus || false; vm.STATE = null; vm.errorOnSkip = false; - vm.showAuthMessage = null; + vm.showCaptchaForm = null; vm.voteProposalRedirectURI = null; var slug = vm.topic.slug; @@ -68,6 +72,21 @@ vm.message = data.message; }); + + // Load captcha + var stop = null; + stop = vm.$interval(function(){ + var $el = angular.element('#serpro_captcha'); + + if ($el && $el.length > 0 ){ + vm.$window.initCaptcha($el[0]); + vm.$interval.cancel(stop); + stop = undefined; + }else{ + vm.$log.debug('captcha element not found.'); + } + + }, 10); }; ProposalBoxController.prototype.showContent = function (slug) { @@ -81,18 +100,56 @@ }); }; + ProposalBoxController.prototype.canVote = function () { + return false; + }; + + ProposalBoxController.prototype.submitCaptcha = function ($event, captchaForm) { + var vm = this; + + var target = $event.target; + var $target = angular.element(target); + var $captcha = $target.find('[name="txtToken_captcha_serpro_gov_br"]'); + + vm.sendingCaptcha = true; + vm.AuthService.loginCaptcha({ + captcha_text: captchaForm.captcha_text.$modelValue, + txtToken_captcha_serpro_gov_br: $captcha.val() + }).then(function(data) { + // SUCCESS + vm.$log.debug('register success.data', data); + + // get captcha_token + }, function(data) { + // ERROR + vm.$log.debug('register error.data', data); + + vm.sendingCaptchaError = {code: data.status }; + + if(data.status === 404){ + vm.$log.error('The api service is out!?'); + } + + }, function(data){ + // UPDATE + vm.$log.debug('register update.data', data); + }).finally(function(){ + vm.sendingCaptcha = false; + }); + }; + ProposalBoxController.prototype.vote = function (value) { var vm = this; - if(vm.$rootScope.currentUser){ + if(vm.canVote()){ vm.$scope.$emit('proposal-box:vote', { OPTION: value, proposal_id: vm.proposal.id }); vm.$log.debug('Sending vote', value); }else{ - vm.$log.info('Must be logged in...'); - vm.showAuthMessage = true; + vm.$log.debug('You cannot vote.'); + vm.showCaptchaForm = true; } }; @@ -135,7 +192,7 @@ proposal: '=', topic: '=', category: '=', - canVote: '=', + showVote: '=', focus: '@' // @ -> Text binding / one-way binding // = -> Direct model binding / two-way binding diff --git a/src/app/components/proposal-box/proposal-box.html b/src/app/components/proposal-box/proposal-box.html index 4c1d1aa..0bb7db3 100644 --- a/src/app/components/proposal-box/proposal-box.html +++ b/src/app/components/proposal-box/proposal-box.html @@ -65,18 +65,48 @@ -