Commit c4363d4273b438e39dfe8d655991e0fabad15b7a

Authored by Leonardo Merlin
2 parents b4811d73 1b9fcc1a

Merge branch 'fix-social'

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