login

In the following code the callback checkLogin() isn’t called untill after the dialogCallBack() is called. It should always close the dialog as an accepted user/pass combo but you get one failed attempt and on the second it works.(level is a global var). The idea is that in checkLogin I can evaluate rpcResponse and based on the results show or hide different section of the webpage in essence a login with access levels.

function initLogin() {
	isc.showLoginDialog(function (credentials, dialogCallBack) {
		var request = isc.RPCRequest.create({
			actionURL: "checkcred.php",
			httpMethod: "GET",
			contentType: "text/xml",
			params: {name: credentials.username, pass: credentials.password},
			useSimpleHttp: false,
			serverOutputAsString: true,
			callback: "checkLogin(rpcResponse)"
		})
		isc.RPCManager.sendRequest(request);
		dialogCallBack(level);
	})
}

function checkLogin(response) {
	level = true;
}

Hi DocSeussMan,

You are intended to call the dialogCallback only after you have determined whether the credentials are valid. Your code below calls it immediately, while “level” is still false, and so credentials will always be considered bad once. You could fix your code by calling dialogCallback from checkLogin(), which will be called only once a response has been received from the server.

See the inline example for showLoginDialog for more details.

Thanks for the response and calling dialogcallback from checklogin seemed like the right choice(that is the way i had it on my initial try) but dialogcallback has no scope in checklogin even if I try to pass it as another variable in the callback.
checklogin(rpcResponse, dialogCallback). This just seems further complicated as there is no way(at least none that i’ve been able to find) to access rpcResponse other then to use a callback from the rpcRequest. The easiest way it seems would be no callback defined in the rpcRequest and just use dialogCallBack(checkLogin(rpcResponse)).

Hi DocSeussMan,

In JavaScript, a function like “dialogCallback” can be stored just like any other JavaScript variable. You could, for example, pass it as part of the rpcRequest, which is accessible from the RPC callback. Or you could store it globally. Or anything you want.

What you can’t do is immediately call dialogCallback without waiting for the RPC callback, because at that point, you have not even sent credentials to the server yet.

Right, but I don’t define dialogCallBack it is part of the built in functionality of smartclient’s showLoginDialog. As for waiting I thought maybe the RPCManager.sendRequest() would halt the flow until the request and the request’s callback had been had been finished.

I realize i can accomplish all of this by creating my own login dialog and functionality. In the spirit of using a framework I was just trying to get the most out of it.

Good job trying to use framework methods where they exist, however, what you’re not grasping here is basic JavaScript techniques, not something to do with SmartClient. Here is corrected code:

function initLogin() {
	isc.showLoginDialog(function (credentials, dialogCallBack) {
		var request = isc.RPCRequest.create({
			actionURL: "checkcred.php",
			httpMethod: "GET",
			contentType: "text/xml",
			params: {name: credentials.username, 
                                     pass: credentials.password},
			useSimpleHttp: false,
			serverOutputAsString: true,
			callback: "checkLogin(rpcResponse[b], rpcRequest[/b])",
                        [b]myDialogCallback : dialogCallback[/b]
		})
		isc.RPCManager.sendRequest(request);
	})
}

function checkLogin(response[b], request[/b]) {
	level = true;
        [b]request.myDialogCallback(level);[/b]
}

I suggest you also take a second look at the code sample in the documentation as it demonstrates an alternative approach using a powerful JavaScript capability called “closures” or just nested functions.

Thanks again for taking the time to help me out and for the advice. Never dawned on me to use something like myDialogCallBack and pass the whole request object to the checkLogin. Thanks again learn something everyday.