Commit f5e0759dd33b824a99825b6b4c5aba61608c3367
1 parent
59545714
Exists in
master
and in
5 other branches
fix login handler (fix #325)
Showing
1 changed file
with
41 additions
and
10 deletions
Show diff stats
js/main.js
| @@ -657,8 +657,9 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -657,8 +657,9 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 657 | showLogout: function(){ | 657 | showLogout: function(){ |
| 658 | $('#login-button').hide(); | 658 | $('#login-button').hide(); |
| 659 | var name = ''; | 659 | var name = ''; |
| 660 | - if(this.user){ | ||
| 661 | - name = this.user.person.name + ' - '; | 660 | + var user = Main.getUser(); |
| 661 | + if(user){ | ||
| 662 | + name = user.person.name + ' - '; | ||
| 662 | } | 663 | } |
| 663 | $('#logout-button .name').text(name); | 664 | $('#logout-button .name').text(name); |
| 664 | $('#logout-button').show(); | 665 | $('#logout-button').show(); |
| @@ -830,6 +831,10 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -830,6 +831,10 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 830 | .removeClass('col-sm-4') | 831 | .removeClass('col-sm-4') |
| 831 | .addClass('col-sm-12'); | 832 | .addClass('col-sm-12'); |
| 832 | 833 | ||
| 834 | + if(logged_in){ | ||
| 835 | + Main.showLogout(); | ||
| 836 | + } | ||
| 837 | + | ||
| 833 | $(document).on('click', '#login-button', function (e){ | 838 | $(document).on('click', '#login-button', function (e){ |
| 834 | e.preventDefault(); | 839 | e.preventDefault(); |
| 835 | loginButton = $(this); | 840 | loginButton = $(this); |
| @@ -1071,7 +1076,6 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -1071,7 +1076,6 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 1071 | //withCredentials: true | 1076 | //withCredentials: true |
| 1072 | } | 1077 | } |
| 1073 | }).done(function(data) { | 1078 | }).done(function(data) { |
| 1074 | - $(document).trigger('login:success', data); | ||
| 1075 | 1079 | ||
| 1076 | var $sectionContent = $form.closest('.section-content'); | 1080 | var $sectionContent = $form.closest('.section-content'); |
| 1077 | if($sectionContent && $sectionContent.length > 0){ | 1081 | if($sectionContent && $sectionContent.length > 0){ |
| @@ -1083,8 +1087,8 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -1083,8 +1087,8 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 1083 | $loginPanel.hide(); | 1087 | $loginPanel.hide(); |
| 1084 | } | 1088 | } |
| 1085 | 1089 | ||
| 1090 | + $(document).trigger('login:success', data); | ||
| 1086 | }).fail(function(data) { | 1091 | }).fail(function(data) { |
| 1087 | - $(document).trigger('login:fail', data); | ||
| 1088 | 1092 | ||
| 1089 | $message.show(); | 1093 | $message.show(); |
| 1090 | if(data.status==401){ | 1094 | if(data.status==401){ |
| @@ -1092,6 +1096,8 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -1092,6 +1096,8 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 1092 | }else{ | 1096 | }else{ |
| 1093 | $message.text('Um erro inesperado ocorreu'); | 1097 | $message.text('Um erro inesperado ocorreu'); |
| 1094 | } | 1098 | } |
| 1099 | + | ||
| 1100 | + $(document).trigger('login:fail', data); | ||
| 1095 | }); | 1101 | }); |
| 1096 | }); | 1102 | }); |
| 1097 | 1103 | ||
| @@ -1135,9 +1141,10 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -1135,9 +1141,10 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 1135 | message.text(''); | 1141 | message.text(''); |
| 1136 | 1142 | ||
| 1137 | var signup = $(this).parents('form.signup'); | 1143 | var signup = $(this).parents('form.signup'); |
| 1138 | - var loading = $('.login-container .loading'); | ||
| 1139 | - loading.show(); | 1144 | + var $loading = $('.login-container .loading'); |
| 1145 | + $loading.show(); | ||
| 1140 | signup.hide(); | 1146 | signup.hide(); |
| 1147 | + signup.removeClass('hide'); | ||
| 1141 | var button = $(this); | 1148 | var button = $(this); |
| 1142 | 1149 | ||
| 1143 | $.ajax({ | 1150 | $.ajax({ |
| @@ -1145,15 +1152,39 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | @@ -1145,15 +1152,39 @@ define(['jquery', 'handlebars', 'fastclick', 'handlebars_helpers', 'piwik'], fun | ||
| 1145 | url: host + '/api/v1/register', | 1152 | url: host + '/api/v1/register', |
| 1146 | data: $(this).parents('.signup').serialize(), | 1153 | data: $(this).parents('.signup').serialize(), |
| 1147 | }).done(function(data) { | 1154 | }).done(function(data) { |
| 1148 | - Main.loginCallback(true, data.private_token); | ||
| 1149 | - Main.displaySuccess(button.closest('.section-content'), 'Cadastro efetuado com sucesso', 1000, 'icon-user-created'); | 1155 | + |
| 1156 | + var $sectionContent = button.closest('.section-content'); | ||
| 1157 | + if($sectionContent && $sectionContent.length > 0){ | ||
| 1158 | + Main.displaySuccess($sectionContent, 'Cadastro efetuado com sucesso', 1000, 'icon-user-created'); | ||
| 1159 | + } | ||
| 1160 | + | ||
| 1161 | + $(document).trigger('login:success', data); | ||
| 1150 | }).fail(function(data) { | 1162 | }).fail(function(data) { |
| 1151 | - var msg = Main.responseToText(data.responseJSON.message); | 1163 | + var msg = ""; |
| 1164 | + try{ | ||
| 1165 | + msg = Main.responseToText(data.responseJSON.message); | ||
| 1166 | + }catch(ex){ | ||
| 1167 | + var ptBR = {}; | ||
| 1168 | + // (Invalid request) email can't be saved | ||
| 1169 | + ptBR['(Invalid request) email can\'t be saved'] = 'E-mail inválido.'; | ||
| 1170 | + // (Invalid request) login can't be saved | ||
| 1171 | + ptBR['(Invalid request) login can\'t be saved'] = 'Nome de usuário inválido.'; | ||
| 1172 | + | ||
| 1173 | + msg = ptBR[data.responseJSON.message] || data.responseJSON.message; | ||
| 1174 | + } | ||
| 1175 | + | ||
| 1152 | message.show(); | 1176 | message.show(); |
| 1153 | message.html('Não foi possível efetuar o cadastro: <br/><br/>' + msg); | 1177 | message.html('Não foi possível efetuar o cadastro: <br/><br/>' + msg); |
| 1178 | + | ||
| 1179 | + $(document).trigger('login:fail', data); | ||
| 1154 | }).always(function() { | 1180 | }).always(function() { |
| 1155 | - loading.hide(); | 1181 | + $loading.hide(); |
| 1156 | signup.show(); | 1182 | signup.show(); |
| 1183 | + | ||
| 1184 | + // var $loginPanel = $loading.closest('#login-panel'); | ||
| 1185 | + // if($loginPanel && $loginPanel.length > 0){ | ||
| 1186 | + // $loginPanel.hide(); | ||
| 1187 | + // } | ||
| 1157 | }); | 1188 | }); |
| 1158 | grecaptcha.reset(); | 1189 | grecaptcha.reset(); |
| 1159 | e.preventDefault(); | 1190 | e.preventDefault(); |