From b3e7d5cbe6b2e1c05b2467f320dad1444d00d60f Mon Sep 17 00:00:00 2001
From: Leonardo Merlin
Date: Fri, 11 Sep 2015 17:19:42 -0300
Subject: [PATCH] Sync
---
src/app/components/auth/auth.service.js | 10 ++++++----
src/app/index.run.js | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
src/app/pages/auth/auth.controller.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++------------
src/app/pages/auth/signin.html | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------------------
src/index.html | 1 +
5 files changed, 165 insertions(+), 96 deletions(-)
diff --git a/src/app/components/auth/auth.service.js b/src/app/components/auth/auth.service.js
index d5bef9f..f514795 100644
--- a/src/app/components/auth/auth.service.js
+++ b/src/app/components/auth/auth.service.js
@@ -8,10 +8,10 @@
.factory('AuthInterceptor', AuthInterceptor);
/** @ngInject */
- function AuthService($http, $rootScope, Session, AUTH_EVENTS, API, $log) {
+ function AuthService($q, $http, $rootScope, Session, AUTH_EVENTS, API, PATH, $log) {
function register (data){
- var url = API.host + '/api/v1/register';
+ var url = PATH.host + '/api/v1/register';
$log.debug('data', data);
// var encodedData = data;
var encodedData = '';
@@ -22,6 +22,8 @@
encodedData += '&password=' + data.password;
encodedData += '&password_confirmation=' + data.password_confirmation;
encodedData += '&user_terms_accepted=' + data.user_terms_accepted;
+ encodedData += '&captcha_text=' + data.captcha_text;
+ encodedData += '&txtToken_captcha_serpro_gov_br=' + data.txtToken_captcha_serpro_gov_br;
// var encodedData = _encodeObj(data);
// var encodedData = angular.element.param(data);
@@ -44,8 +46,8 @@
}, function(response) {
$log.debug('AuthService.register [FAIL] response', response);
- $rootScope.$broadcast(AUTH_EVENTS.registerFailed);
- return response;
+ $rootScope.$broadcast(AUTH_EVENTS.registerFailed, response);
+ return $q.reject(response);
});
}
diff --git a/src/app/index.run.js b/src/app/index.run.js
index 04a4372..569fe3c 100644
--- a/src/app/index.run.js
+++ b/src/app/index.run.js
@@ -4,12 +4,13 @@
angular
.module('dialoga')
- .run(runAuth)
- .run(runSocialAuth)
.run(runAccessibility)
+ .run(runAuth)
+ .run(runCaptcha)
+ .run(runColorUtils)
.run(runHistory)
.run(runPath)
- .run(runColorUtils)
+ .run(runSocialAuth)
.run(runUtils)
.run(runBlock);
@@ -45,18 +46,53 @@
}
/** @ngInject */
+ function runCaptcha($window, $log, GUID) {
+ var serpro_captcha_clienteId = 'fdbcdc7a0b754ee7ae9d865fda740f17';
+
+ $window.initCaptcha = function(element) {
+ var $element = angular.element(element);
+
+ // already have a started captcha
+ if ($element.data('captcha')) {
+ $log.info('Captcha already initialized. Abort.');
+ return;
+ }
+
+ // Create a new instance of Captcha
+ var oCaptcha_serpro_gov_br = new $window.captcha_serpro_gov_br();
+
+ // Set the initial data
+ $element.val('');
+ $element.data('captcha', oCaptcha_serpro_gov_br);
+ oCaptcha_serpro_gov_br.clienteId = serpro_captcha_clienteId;
+ // oCaptcha_serpro_gov_br.url = "/serprocaptcha";
+ oCaptcha_serpro_gov_br.criarUI(element, 'css', 'serpro_captcha_component_', GUID.generate());
+ };
+
+ $window.reloadCaptcha = function(element) {
+ var $element = angular.element(element);
+
+ if ($element.data('captcha')) {
+ $element.data('captcha').recarregar();
+ }
+ };
+
+ $log.debug('runCaptcha');
+ }
+
+ /** @ngInject */
function runSocialAuth($window, $rootScope, $interval, $log) {
- $window.oauthClientAction = function (url){
+ $window.oauthClientAction = function(url) {
var child = $window.open(url, '_blank');
var interval = $interval(function() {
try {
- if(!child.closed) {
+ if (!child.closed) {
child.postMessage({
message: 'requestOauthClientPluginResult'
}, '*');
}
- } catch(e) {
+ } catch (e) {
// we're here when the child window has been navigated away or closed
if (child.closed) {
$interval.cancel(interval);
@@ -118,7 +154,7 @@
// prevent skip link from redirecting
if ($event) { $event.preventDefault(); }
- if(angular.isString(target)){
+ if (angular.isString(target)) {
target = angular.element(target);
}
@@ -137,7 +173,7 @@
$rootScope.$previousState.splice(-MAX_HISTORY, MAX_HISTORY);
});
- $rootScope.goBack = $rootScope.goBack || function () {
+ $rootScope.goBack = $rootScope.goBack || function() {
return $rootScope.$previousState.pop();
};
}
@@ -178,7 +214,7 @@
/** @ngInject */
function runUtils($rootScope) {
- $rootScope.stripHtml = function (text) {
+ $rootScope.stripHtml = function(text) {
return String(text).replace(/<[^>]+>/gm, '');
};
}
diff --git a/src/app/pages/auth/auth.controller.js b/src/app/pages/auth/auth.controller.js
index b85a5fe..deba871 100644
--- a/src/app/pages/auth/auth.controller.js
+++ b/src/app/pages/auth/auth.controller.js
@@ -6,7 +6,7 @@
.controller('AuthPageController', AuthPageController);
/** @ngInject */
- function AuthPageController($scope, $rootScope, $window, $location, $state, $timeout, AUTH_EVENTS, AuthService, DialogaService, Session, $log) {
+ function AuthPageController($scope, $rootScope, $window, $location, $state, $timeout, $interval, AUTH_EVENTS, AuthService, DialogaService, Session, $log) {
var vm = this;
vm.$scope = $scope;
@@ -15,6 +15,7 @@
vm.$location = $location;
vm.$state = $state;
vm.$timeout = $timeout;
+ vm.$interval = $interval;
vm.AUTH_EVENTS = AUTH_EVENTS;
vm.AuthService = AuthService;
vm.DialogaService = DialogaService;
@@ -78,14 +79,38 @@
AuthPageController.prototype.attachListeners = function() {
var vm = this;
+ vm.$scope.$on(vm.AUTH_EVENTS.registerSuccess, function(event, response) {
+ vm.$log.debug('TODO: handle register success');
+ vm.$log.debug('[register success] response', response);
+ });
+
+ vm.$scope.$on(vm.AUTH_EVENTS.registerFailed, function(event, response) {
+ vm.$log.debug('TODO: handle register error');
+ vm.$log.debug('[register error] response', response);
+
+ var reason = response.data.message;
+ vm.errorMessage = reason;
+ });
+
vm.$scope.$on('oauthClientPluginResult', function(event, response) {
vm.$log.debug('response', response);
// var logged_id = response.data.logged_id;
// var private_token = response.data.private_token;
// var user = response.data.user;
-
});
+
+ 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;
+ }
+
+ }, 200);
};
AuthPageController.prototype.onClickLogout = function() {
@@ -94,7 +119,7 @@
vm.AuthService.logout();
};
- AuthPageController.prototype.submitSigup = function(credentials) {
+ AuthPageController.prototype.submitSingup = function(credentials) {
var vm = this;
vm.AuthService.register(credentials).then(function(response) {
@@ -108,8 +133,19 @@
}, function(response) {
vm.$log.debug('register error.response', response);
+ var message = response.data.message;
+ vm.errorMessage = message;
+
+ if(response.data.code === 500){
+ vm.internalError = true;
+ }
+
+
// TODO: mensagens de erro
// TODO: tratar multiplos erros
+
+ // javascript_console_message: "Unable to reach Serpro's Captcha validation service"
+ // message: "Internal captcha validation error"
});
};
@@ -137,15 +173,14 @@
// start countdown
vm.countdown = vm.delay;
- (function countdown() {
- vm.$timeout(function() {
- vm.countdown--;
- vm.$log.debug('vm.countdown', vm.countdown);
- if (vm.countdown > 0) {
- countdown();
- }
- }, 1000);
- })();
+ var stop = null;
+ stop = vm.$interval(function() {
+ vm.countdown--;
+ if (vm.countdown <= 0) {
+ vm.$interval.cancel(stop);
+ stop = undefined;
+ }
+ }, 1000);
vm.$timeout(function() {
var state = vm.params.state;
diff --git a/src/app/pages/auth/signin.html b/src/app/pages/auth/signin.html
index 6d3c06c..76595bd 100644
--- a/src/app/pages/auth/signin.html
+++ b/src/app/pages/auth/signin.html
@@ -82,92 +82,87 @@
-
-
-
-
-
-
+
+
+
+ {{pageSignin.errorMessage}}
+
+
+
Este erro parece ser um problema interno.
Por favor, tente novamente mais tarde.
+
Caso o problema persista, entre em contato!
+
Ir para página de contato
+