Commit c4363d4273b438e39dfe8d655991e0fabad15b7a

Authored by Leonardo Merlin
2 parents b4811d73 1b9fcc1a

Merge branch 'fix-social'

src/app/index.run.js
@@ -267,11 +267,10 @@ @@ -267,11 +267,10 @@
267 }; 267 };
268 268
269 $window.addEventListener('message', function(eventMessage) { 269 $window.addEventListener('message', function(eventMessage) {
270 - // $log.debug('eventMessage', eventMessage);  
271 270
272 if (eventMessage.data.message === 'oauthClientPluginResult') { 271 if (eventMessage.data.message === 'oauthClientPluginResult') {
273 $rootScope.$broadcast('oauthClientPluginResult', eventMessage); 272 $rootScope.$broadcast('oauthClientPluginResult', eventMessage);
274 - // eventMessage.source.close(); 273 + eventMessage.source.close();
275 } 274 }
276 }); 275 });
277 } 276 }
src/app/pages/auth/auth.controller.js
@@ -46,7 +46,7 @@ @@ -46,7 +46,7 @@
46 vm.search = vm.$location.search(); 46 vm.search = vm.$location.search();
47 var redirect = vm.search.redirect_uri || ''; 47 var redirect = vm.search.redirect_uri || '';
48 if (redirect && redirect.length > 0) { 48 if (redirect && redirect.length > 0) {
49 - vm.params = JSON.parse('{"' + decodeURI(redirect).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}'); 49 + vm.params = JSON.parse('{"' + decodeURI(redirect).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
50 vm.hasRedirect = true; 50 vm.hasRedirect = true;
51 } 51 }
52 52
@@ -99,9 +99,22 @@ @@ -99,9 +99,22 @@
99 vm.$scope.$on('oauthClientPluginResult', function(event, response) { 99 vm.$scope.$on('oauthClientPluginResult', function(event, response) {
100 vm.$log.debug('response', response); 100 vm.$log.debug('response', response);
101 101
102 - // var logged_id = response.data.logged_id;  
103 - // var private_token = response.data.private_token;  
104 - // var user = response.data.user; 102 + var logged_in = response.data.logged_in;
  103 + var message = response.data.message;
  104 + var private_token = response.data.private_token;
  105 +
  106 + // Garante que o 'user' sempre terá a propriedade 'private_token'
  107 + if(response.data.user && !response.data.user.private_token){
  108 + response.data.user.private_token = private_token;
  109 + }
  110 +
  111 + // Se o usuário autorizou o login via a rede social, 'logged_in' é 'true'
  112 + if (logged_in) {
  113 + var currentUser = vm.Session.create(response.data);
  114 +
  115 + vm.$rootScope.currentUser = currentUser;
  116 + vm.$rootScope.$broadcast(vm.AUTH_EVENTS.loginSuccess, currentUser);
  117 + }
105 }); 118 });
106 119
107 vm._attachCaptcha(); 120 vm._attachCaptcha();
@@ -111,10 +124,10 @@ @@ -111,10 +124,10 @@
111 var vm = this; 124 var vm = this;
112 125
113 var stop = null; 126 var stop = null;
114 - stop = vm.$interval(function(){ 127 + stop = vm.$interval(function() {
115 var $el = angular.element('#serpro_captcha'); 128 var $el = angular.element('#serpro_captcha');
116 129
117 - if ($el && $el.length > 0 ){ 130 + if ($el && $el.length > 0) {
118 vm.$window.initCaptcha($el[0]); 131 vm.$window.initCaptcha($el[0]);
119 vm.$interval.cancel(stop); 132 vm.$interval.cancel(stop);
120 stop = undefined; 133 stop = undefined;
@@ -155,15 +168,15 @@ @@ -155,15 +168,15 @@
155 vm.signupErrorMessage = response.data.message; 168 vm.signupErrorMessage = response.data.message;
156 169
157 // 4xx client error 170 // 4xx client error
158 - if (response.status >= 400 && response.status < 500){ 171 + if (response.status >= 400 && response.status < 500) {
159 var errors = JSON.parse(response.data.message); 172 var errors = JSON.parse(response.data.message);
160 - if(errors && errors.email){ 173 + if (errors && errors.email) {
161 vm.signupErrorMessage = 'E-mail já está em uso.'; 174 vm.signupErrorMessage = 'E-mail já está em uso.';
162 } 175 }
163 } 176 }
164 177
165 // 5xx server error 178 // 5xx server error
166 - if (response.status >= 500 && response.status < 600){ 179 + if (response.status >= 500 && response.status < 600) {
167 vm.internalError = true; 180 vm.internalError = true;
168 } 181 }
169 }); 182 });
@@ -184,12 +197,12 @@ @@ -184,12 +197,12 @@
184 vm.signinError = true; 197 vm.signinError = true;
185 198
186 // 4xx client error 199 // 4xx client error
187 - if ( response.status >= 400 && response.status < 500 ) { 200 + if (response.status >= 400 && response.status < 500) {
188 201
189 vm.signinErrorTitle = 'Erro!'; 202 vm.signinErrorTitle = 'Erro!';
190 vm.signinErrorContent = response.data.message; 203 vm.signinErrorContent = response.data.message;
191 204
192 - if(response.status === 401){ 205 + if (response.status === 401) {
193 vm.signinErrorTitle = 'Acesso não autorizado!'; 206 vm.signinErrorTitle = 'Acesso não autorizado!';
194 vm.signinErrorContent = 'E-mail ou senha incorretos.'; 207 vm.signinErrorContent = 'E-mail ou senha incorretos.';
195 } 208 }
@@ -221,27 +234,27 @@ @@ -221,27 +234,27 @@
221 }); 234 });
222 235
223 // ERROR 236 // ERROR
224 - promiseRequest.catch(function(response){ 237 + promiseRequest.catch(function(response) {
225 vm.$log.debug('recover error.response', response); 238 vm.$log.debug('recover error.response', response);
226 239
227 vm.recoverError = true; 240 vm.recoverError = true;
228 vm.recoverErrorMessage = response.data.message; 241 vm.recoverErrorMessage = response.data.message;
229 242
230 // Client Error 243 // Client Error
231 - if (response.status >= 400 && response.status < 500){  
232 - if(response.status === 404){ 244 + if (response.status >= 400 && response.status < 500) {
  245 + if (response.status === 404) {
233 vm.recoverErrorMessage = 'E-mail não cadastrado no Dialoga Brasil.'; 246 vm.recoverErrorMessage = 'E-mail não cadastrado no Dialoga Brasil.';
234 } 247 }
235 } 248 }
236 249
237 // Server Error 250 // Server Error
238 - if (response.status >= 500 && response.status < 600){ 251 + if (response.status >= 500 && response.status < 600) {
239 vm.internalError = true; 252 vm.internalError = true;
240 } 253 }
241 }); 254 });
242 255
243 // ALWAYS 256 // ALWAYS
244 - promiseRequest.finally(function(){ 257 + promiseRequest.finally(function() {
245 vm.loadingSubmitRecover = false; 258 vm.loadingSubmitRecover = false;
246 }); 259 });
247 }; 260 };
@@ -266,15 +279,15 @@ @@ -266,15 +279,15 @@
266 279
267 // Feedback para usuário já ativo na plataforma 280 // Feedback para usuário já ativo na plataforma
268 var user = response.data.users[0]; 281 var user = response.data.users[0];
269 - if ( user && (user.activated === true) ) { 282 + if (user && (user.activated === true)) {
270 vm.resendConfirmationSuccessTitle = 'Usuário já está ativo!'; 283 vm.resendConfirmationSuccessTitle = 'Usuário já está ativo!';
271 vm.resendConfirmationSuccessMessage = 'O e-mail informado já foi confirmado.'; 284 vm.resendConfirmationSuccessMessage = 'O e-mail informado já foi confirmado.';
272 - }else{ 285 + }else {
273 vm.resendConfirmationSuccessTitle = 'Pronto!'; 286 vm.resendConfirmationSuccessTitle = 'Pronto!';
274 vm.resendConfirmationSuccessMessage = 'Em instantes você receberá em seu e-mail um link para confirmar o seu cadastro.'; 287 vm.resendConfirmationSuccessMessage = 'Em instantes você receberá em seu e-mail um link para confirmar o seu cadastro.';
275 } 288 }
276 289
277 - }, function(response){ 290 + }, function(response) {
278 vm.$log.debug('resendConfirmation error.response', response); 291 vm.$log.debug('resendConfirmation error.response', response);
279 292
280 vm.resendConfirmationError = true; 293 vm.resendConfirmationError = true;
@@ -284,10 +297,10 @@ @@ -284,10 +297,10 @@
284 // if (response.status >= 400 && response.status < 500){} 297 // if (response.status >= 400 && response.status < 500){}
285 298
286 // Server Error 299 // Server Error
287 - if (response.status >= 500 && response.status < 600){ 300 + if (response.status >= 500 && response.status < 600) {
288 vm.internalError = true; 301 vm.internalError = true;
289 } 302 }
290 - }).catch(function(error){ 303 + }).catch(function(error) {
291 vm.$log.debug('resendConfirmation catch.error', error); 304 vm.$log.debug('resendConfirmation catch.error', error);
292 }); 305 });
293 }; 306 };
@@ -370,7 +383,7 @@ @@ -370,7 +383,7 @@
370 vm.$window.oauthClientAction(url); 383 vm.$window.oauthClientAction(url);
371 }; 384 };
372 385
373 - function getCaptchaValFromEvent($event){ 386 + function getCaptchaValFromEvent($event) {
374 return angular.element($event.target).find('[name="txtToken_captcha_serpro_gov_br"]').val(); 387 return angular.element($event.target).find('[name="txtToken_captcha_serpro_gov_br"]').val();
375 } 388 }
376 })(); 389 })();