Commit d13b205cdabe2bcb1e52cb7d5764be33d2ecfaea

Authored by Caio Almeida
1 parent aeb85a1e

Fixing bug with login persistence

ConfJuvApp/builds/confjuv-dev.apk
No preview for this file type
ConfJuvApp/builds/confjuvapp-live.apk
No preview for this file type
ConfJuvApp/builds/confjuvapp-web.zip
No preview for this file type
ConfJuvApp/config.xml
1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 1 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 -<widget id="com.ionicframework.confjuvapp748431" version="0.0.25" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> 2 +<widget id="com.ionicframework.confjuvapp748431" version="0.0.26" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
3 <name>#3ConfJuv</name> 3 <name>#3ConfJuv</name>
4 <description>Aplicativo móvel para 3ª Conferência Nacional de Juventude</description> 4 <description>Aplicativo móvel para 3ª Conferência Nacional de Juventude</description>
5 <author email="confjuvapp@gmail.com" href="http://www.juventude.gov.br/"></author> 5 <author email="confjuvapp@gmail.com" href="http://www.juventude.gov.br/"></author>
ConfJuvApp/www/js/controllers.js
@@ -21,12 +21,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -21,12 +21,7 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
21 // Function to open the modal 21 // Function to open the modal
22 $scope.openModal = function() { 22 $scope.openModal = function() {
23 if (ConfJuvAppUtils.getPrivateToken()) { 23 if (ConfJuvAppUtils.getPrivateToken()) {
24 - $scope.token = ConfJuvAppUtils.getPrivateToken();  
25 - $scope.loggedIn = true;  
26 $scope.loadMe(); 24 $scope.loadMe();
27 - $scope.loadTopics($scope.token);  
28 - $scope.loadStages();  
29 - $scope.parseURLParams();  
30 } else if ($scope.modal) { 25 } else if ($scope.modal) {
31 $scope.modal.show(); 26 $scope.modal.show();
32 } else { 27 } else {
@@ -83,7 +78,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -83,7 +78,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
83 $scope.openModal(); 78 $scope.openModal();
84 }; 79 };
85 80
86 -  
87 // Function to close the modal 81 // Function to close the modal
88 $scope.closeModal = function() { 82 $scope.closeModal = function() {
89 $scope.modal.hide(); 83 $scope.modal.hide();
@@ -109,19 +103,13 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -109,19 +103,13 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
109 timeout: 10000 103 timeout: 10000
110 } 104 }
111 105
112 -  
113 $http.post(ConfJuvAppUtils.pathTo('login'), jQuery.param(data), config) 106 $http.post(ConfJuvAppUtils.pathTo('login'), jQuery.param(data), config)
114 .then(function(resp) { 107 .then(function(resp) {
115 $scope.closeModal(); 108 $scope.closeModal();
116 var popup = $ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' }); 109 var popup = $ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' });
117 - $scope.loggedIn = true;  
118 $scope.user = resp.data.person; 110 $scope.user = resp.data.person;
119 popup.then(function() { 111 popup.then(function() {
120 - $scope.token = resp.data.private_token;  
121 - ConfJuvAppUtils.setPrivateToken($scope.token);  
122 - $scope.loadTopics(resp.data.private_token);  
123 - $scope.loadStages();  
124 - $scope.parseURLParams(); 112 + $scope.loginCallback(resp.data.private_token);
125 }); 113 });
126 }, function(err) { 114 }, function(err) {
127 $scope.closeModal(); 115 $scope.closeModal();
@@ -134,6 +122,15 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -134,6 +122,15 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
134 }); 122 });
135 }; 123 };
136 124
  125 + $scope.loginCallback = function(token) {
  126 + $scope.loggedIn = true;
  127 + $scope.token = token;
  128 + ConfJuvAppUtils.setPrivateToken(token);
  129 + $scope.loadTopics(token);
  130 + $scope.loadStages();
  131 + $scope.parseURLParams();
  132 + };
  133 +
137 // Function to retrieve password 134 // Function to retrieve password
138 135
139 $scope.forgotPassword = function(email) { 136 $scope.forgotPassword = function(email) {
@@ -261,15 +258,17 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -261,15 +258,17 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
261 $scope.loadMe = function() { 258 $scope.loadMe = function() {
262 $scope.loading = true; 259 $scope.loading = true;
263 260
264 - var params = '?private_token=' + ConfJuvAppUtils.getPrivateToken();  
265 - var path = 'people/me/' +params; 261 + var params = '?private_token=' + ConfJuvAppUtils.getPrivateToken(),
  262 + path = 'people/me/' + params;
266 263
267 $http.get(ConfJuvAppUtils.pathTo(path)) 264 $http.get(ConfJuvAppUtils.pathTo(path))
268 .then(function(resp) { 265 .then(function(resp) {
269 $scope.user = resp.data.person; 266 $scope.user = resp.data.person;
  267 + $scope.loginCallback(ConfJuvAppUtils.getPrivateToken());
270 $scope.loading = false; 268 $scope.loading = false;
271 }, function(err) { 269 }, function(err) {
272 $scope.token = ConfJuvAppUtils.setPrivateToken(null); 270 $scope.token = ConfJuvAppUtils.setPrivateToken(null);
  271 + $scope.loggedIn = false;
273 var popup = $ionicPopup.alert({ title: 'Usuário', template: 'Sessão expirada. Por favor faça login novamente.' }); 272 var popup = $ionicPopup.alert({ title: 'Usuário', template: 'Sessão expirada. Por favor faça login novamente.' });
274 popup.then(function() { 273 popup.then(function() {
275 $scope.openModal(); 274 $scope.openModal();
@@ -278,8 +277,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, []) @@ -278,8 +277,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
278 }); 277 });
279 }; 278 };
280 279
281 -  
282 -  
283 $scope.backToLoginHome = function() { 280 $scope.backToLoginHome = function() {
284 $scope.registerFormDisplayed = false; 281 $scope.registerFormDisplayed = false;
285 $scope.loginFormDisplayed = false; 282 $scope.loginFormDisplayed = false;