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 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 3 <name>#3ConfJuv</name>
4 4 <description>Aplicativo móvel para 3ª Conferência Nacional de Juventude</description>
5 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 21 // Function to open the modal
22 22 $scope.openModal = function() {
23 23 if (ConfJuvAppUtils.getPrivateToken()) {
24   - $scope.token = ConfJuvAppUtils.getPrivateToken();
25   - $scope.loggedIn = true;
26 24 $scope.loadMe();
27   - $scope.loadTopics($scope.token);
28   - $scope.loadStages();
29   - $scope.parseURLParams();
30 25 } else if ($scope.modal) {
31 26 $scope.modal.show();
32 27 } else {
... ... @@ -83,7 +78,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
83 78 $scope.openModal();
84 79 };
85 80  
86   -
87 81 // Function to close the modal
88 82 $scope.closeModal = function() {
89 83 $scope.modal.hide();
... ... @@ -109,19 +103,13 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
109 103 timeout: 10000
110 104 }
111 105  
112   -
113 106 $http.post(ConfJuvAppUtils.pathTo('login'), jQuery.param(data), config)
114 107 .then(function(resp) {
115 108 $scope.closeModal();
116 109 var popup = $ionicPopup.alert({ title: 'Login', template: 'Login efetuado com sucesso!' });
117   - $scope.loggedIn = true;
118 110 $scope.user = resp.data.person;
119 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 114 }, function(err) {
127 115 $scope.closeModal();
... ... @@ -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 134 // Function to retrieve password
138 135  
139 136 $scope.forgotPassword = function(email) {
... ... @@ -261,15 +258,17 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
261 258 $scope.loadMe = function() {
262 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 264 $http.get(ConfJuvAppUtils.pathTo(path))
268 265 .then(function(resp) {
269 266 $scope.user = resp.data.person;
  267 + $scope.loginCallback(ConfJuvAppUtils.getPrivateToken());
270 268 $scope.loading = false;
271 269 }, function(err) {
272 270 $scope.token = ConfJuvAppUtils.setPrivateToken(null);
  271 + $scope.loggedIn = false;
273 272 var popup = $ionicPopup.alert({ title: 'Usuário', template: 'Sessão expirada. Por favor faça login novamente.' });
274 273 popup.then(function() {
275 274 $scope.openModal();
... ... @@ -278,8 +277,6 @@ angular.module(&#39;confjuvapp.controllers&#39;, [])
278 277 });
279 278 };
280 279  
281   -
282   -
283 280 $scope.backToLoginHome = function() {
284 281 $scope.registerFormDisplayed = false;
285 282 $scope.loginFormDisplayed = false;
... ...