diff options
author | Struan Donald <struan@exo.org.uk> | 2013-04-26 14:59:20 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-04-26 15:17:48 +0100 |
commit | 5c4169e09d865b9d6658dcee56532853671bd590 (patch) | |
tree | 58b329cec2f5beb7b5a53b6cda072ff2f6d4c604 | |
parent | dcc6095c50594278d035a4c29467d1de56cd33f5 (diff) |
check logged in status by using api call
-rw-r--r-- | www/js/app.js | 27 | ||||
-rw-r--r-- | www/js/router.js | 2 | ||||
-rw-r--r-- | www/js/views/login.js | 1 | ||||
-rw-r--r-- | www/js/views/submit.js | 6 |
4 files changed, 30 insertions, 6 deletions
diff --git a/www/js/app.js b/www/js/app.js index 930b6f2..06b9e88 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -41,6 +41,7 @@ var tpl = { 'home', 'around', 'offline', 'save_offline', 'reports', 'login', 'address_search', 'existing', 'photo', 'details', 'submit', 'submit_email', 'submit_name', 'submit_password', 'submit_confirm', 'sent' ], + isLoggedIn: 0, isOffline: 0, initialized: 0, users: new FMS.Users(), @@ -67,6 +68,26 @@ var tpl = { } }, + checkLoggedInStatus: function() { + if ( FMS.isOffline ) { + } else { + $.ajax( { + url: CONFIG.FMS_URL + '/auth/ajax/check_auth', + type: 'GET', + dataType: 'json', + timeout: 30000, + success: function( data, status ) { + console.log(data); + console.log(status); + FMS.isLoggedIn = 1; + }, + error: function() { + FMS.isLoggedIn = 0; + } + } ); + } + }, + saveCurrentDraft: function() { FMS.router.pause(); FMS.allDrafts.add( FMS.currentDraft ); @@ -108,11 +129,6 @@ var tpl = { localStorage.currentDraftID = null; }, - isLoggedIn: function() { - return FMS.currentUser && FMS.currentUser.get('email') && - FMS.currentUser.get('password') && FMS.currentUser.get('name'); - }, - initialize: function () { if ( this.initialized == 1 ) { return this; @@ -147,6 +163,7 @@ var tpl = { FMS.allDrafts.fetch(); FMS.checkOnlineStatus(); FMS.loadCurrentDraft(); + FMS.checkLoggedInStatus(); Backbone.history.start(); navigator.splashscreen.hide(); diff --git a/www/js/router.js b/www/js/router.js index 6d4bb44..0832599 100644 --- a/www/js/router.js +++ b/www/js/router.js @@ -75,7 +75,7 @@ submitStart: function() { var submitView; - if ( FMS.currentUser && FMS.isLoggedIn() ) { + if ( FMS.currentUser && FMS.isLoggedIn ) { submitView = new FMS.SubmitConfirmView({ model: FMS.currentDraft }); } else { submitView = new FMS.SubmitEmailView({ model: FMS.currentDraft }); diff --git a/www/js/views/login.js b/www/js/views/login.js index 62aa325..5f2dfdb 100644 --- a/www/js/views/login.js +++ b/www/js/views/login.js @@ -32,6 +32,7 @@ that.model.set('email', $('#form_email').val()); that.model.set('name', data.name); that.model.save(); + FMS.isLoggedIn = 1; $('#password_row').hide(); $('#success_row').show(); } else { diff --git a/www/js/views/submit.js b/www/js/views/submit.js index 8ab54d7..6a59923 100644 --- a/www/js/views/submit.js +++ b/www/js/views/submit.js @@ -48,6 +48,7 @@ onReportSync: function(model, resp, options) { this.stopListening(); + this.afterSubmit(); if ( FMS.currentUser ) { FMS.currentUser.save(); } @@ -67,6 +68,7 @@ }, beforeSubmit: function() {}, + afterSubmit: function() {}, _destroy: function() { this.stopListening(); @@ -228,6 +230,10 @@ } }, + afterSubmit: function() { + FMS.isLoggedIn = 1; + }, + onReportError: function(model, err, options) { if ( err.check_name ) { $('#form_name').val(err.check_name); |