PDA

View Full Version : Login System



Preston85
20 Aug 2009, 5:07 AM
Hi, I have a simple login form which redirect to my main site. What options are given depends on the users level, the issue is when first loaded the page thinks my variable is undefined. I put a few comments in and the order things were processed wasn't what I expected.



var user_level;

Ext.Ajax.request({
url: './session/assets/fnc/get_user_level.php',
method : 'GET',
success : function(responseObject){
user_level = responseObject.responseText;
},
failure : function(responseObject){
// fail
}
});

// Main View layout
function mainview(){
// Quick tip for forms
Ext.QuickTips.init();

// PANELS
if (user_level < 20) {
// panel def
}
else {
// panel def
}

// more panel def's that are not relivent
};

// Render the layout when browser is ready.
Ext.onReady(mainview);

I thought it might be something to do with the ajax not being ready to do the request so does the rendering first so I've tried putting the request code inside the function but that still doesn't work. It works ok in firefox but internet explorer doesn't like it, I have to refresh and then it finds the variable.

Ta

nicobarten
20 Aug 2009, 5:16 AM
Isn't that because Ajax requests are asynchronous? Because of that, mainview() will load while the ajax stuff is still progressing.

I have almost the same problem as you, based on my authorization system some user groups may not see certain stuff in my application, but because the ajax requests are asynchronously, it's always too late...

I could do it the same way you do (so loading all the authorization stuff for the current user when the application loads and putting it in a variable or object for later usage), however this is very insecure i think. The user should be able to track the name of the variable, and when logged in, be able to change it (by using Firebug for example).

Preston85
21 Aug 2009, 12:40 AM
Any suggestions on how to fix this? Would love to be able to say "use firefox" but really needs to be browser compatible.

Only way I can think of doing it is making the onready part in a while + if statement. Do the request, if null redo request, if not null display mainview. Would that work?

evant
21 Aug 2009, 12:44 AM
var user_level = 0

// Main View layout
function mainview(){
// Quick tip for forms
Ext.QuickTips.init();

// PANELS
if (user_level < 20) {
// panel def
}
else {
// panel def
}

// more panel def's that are not relivent
};

// Render the layout when browser is ready.
Ext.onReady(function(){
Ext.Ajax.request({
url: './session/assets/fnc/get_user_level.php',
method : 'GET',
success : function(responseObject){
user_level = responseObject.responseText;
mainview();
},
failure : function(responseObject){
// something else
}
});
});

Preston85
21 Aug 2009, 12:51 AM
:"> Should of seen that. (goes for ~o))