Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  165] [ 1]  / answers: 1 / hits: 32154  / 13 Years ago, wed, april 27, 2011, 12:00:00

Firstly, should the static page that is served for the app be the login page?



Secondly, my server side code is fine (it won't give any data that the user shouldn't be able to see). But how do I make my app know that if the user is not logged in, to go back to a login form?


More From » jquery

 Answers
5

I have a backend call that my client-side code that my static page (index.php) makes to check whether the current user is logged in. Let's say you have a backend call at api/auth/logged_in which returns HTTP status code 200 if the user is logged in or 400 otherwise (using cookie-based sessions):



appController.checkUser(function(isLoggedIn){
if(!isLoggedIn) {
window.location.hash = login;
}

Backbone.history.start();
});

...

window.AppController = Backbone.Controller.extend({

checkUser: function(callback) {
var that = this;

$.ajax(api/auth/logged_in, {
type: GET,
dataType: json,
success: function() {
return callback(true);
},
error: function() {
return callback(false);
}
});
}
});

[#92525] Tuesday, April 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brianaclaras

Total Points: 23
Total Questions: 106
Total Answers: 111

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;