Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    LoginDialog implementation

    Greetings,

    I'm using Version 8. I originally tried to use isc.showLoginDialog as a quick and easy way to create an admin login. I've never been able to make it work. I've even had others look at it and they can't figure it out either. I've read all of the documentation on it several times. I also looked at the examples.

    I'm passed trying to make it work, but now I'm just curious as to why I can't get it to work. I've tried probably about 6 different variations of the code. The one below is the last iteration. Can you give me a hint as to how this is supposed to work?

    Code:
    isc.showLoginDialog(function (credentials, dialogCallback) {
        if (credentials == null) return; // dismissed
    
        // send credentials    
        sendCredentials(credentials, function (loginSucceeded) {
            // report success or failure
            dialogCallback(loginSucceeded);
        })
    })
    
    function sendCredentials(creds, dialogCallback) {
    	
    	try {
    		isc.DMI.call('VerifyLogin', 'VerifyLoginCtrl', 'validateLogin', creds, dialogCallback);
    	}catch (err) {
    		isc.warn("An exception occurred. " + " Error name: " + err.name + ". Error message: " + err.message);
    	}
    }

    #2
    "dialogCallback" expects one parameter: success or failure. You're passing it to a DMI so it's going to get standard DMI parameters instead of the expected single parameter.

    Comment


      #3
      The DMI call is not passing back standard parameters, but rather a boolean:

      Code:
      	public boolean validateLogin(HttpServletRequest request, Map credentials) {
      		
      		if (credentials.get("username").equals("a2112dmin") && credentials.get("password").equals("fje34ocs")) {
      			System.out.println("returning true");
      			return true;
      		}else{
      			System.out.println("returning false");
      			return false;
      		}
      		
      	}

      Comment


        #4
        The return value of your method does not affect the parameters to the DMI callback. You need to write a callback for the DMI that detects success or failure based on the normal DMI callback parameters, then invokes dialogCallback with a single true or false argument.

        Comment


          #5
          I had tried that before, but I couldn't get my mind around how to invoke the callback. This is how I had it, but it obviously won't work this way. How should I invoked the dialogCallback?

          Code:
          function sendCredentials(creds, dialogCallback) {
          	try {
          		isc.DMI.call('VerifyLogin', 'VerifyLoginCtrl', 'validateLogin', creds, 'loginCallback(rpcResponse)');
          	}catch (err) {
          		isc.warn("An exception occurred. " + " Error name: " + err.name + ". Error message: " + err.message);
          	}
          }
          
          function loginCallback(rpcResponse) {
          	if (if (rpcResponse.data == false) {
          		dialogCallback(false);
          	}else{
          		dialogCallback(true);
          	}
          }

          Comment


            #6
            Other than the syntax error, in isolation that code looks fine. Take a look at what value you're actually passing to track down what's going wrong.

            Comment


              #7
              Below is the entire implementation, other than the java performing the DMI. The rpcResponse parameter in loginCallback contains the value expected. What happens is that an error is thrown at dialogCallback(false); "Object expected", which is what I would expect since it has no idea what dialogCallback is. This is why I couldn't get any further, I could'nt figure out how to invoke dialogCallback, it's not a visible method.

              Code:
              isc.showLoginDialog(function (credentials, dialogCallback) {
                  if (credentials == null) return; // dismissed
                  // send credentials    
                  sendCredentials(credentials, function (loginSucceeded) {
                      // report success or failure
                      dialogCallback(loginSucceeded);
                  })
              })
              
              function sendCredentials(creds, dialogCallback) {
              	try {
              		isc.DMI.call('VerifyLogin', 'VerifyLoginCtrl', 'validateLogin', creds, 'loginCallback(rpcResponse)');
              	}catch (err) {
              		isc.warn("An exception occurred. " + " Error name: " + err.name + ". Error message: " + err.message);
              	}
              }
              
              function loginCallback(rpcResponse) {
              	if (rpcResponse.data == false) {
              		dialogCallback(false);
              	}else{
              		dialogCallback(true);
              	}
              }

              Comment


                #8
                Ah, OK, your confusion comes from JavaScript scoping. If you take the functions that are currently standalone global functions and move that code into the body of the anonymous function passed to sendCredentials, you'll have access to "dialogCallback" as a local variable (this is called lexical scoping or a "closure").

                Alternatively, you can store dialogCallback somewhere as a property of some object, just like you might store any other value such as a String or Number.

                Comment


                  #9
                  Yep, that did the trick. Admittedly, I often get tripped up by closures. It's something I need to get better at.
                  Thanks.

                  Comment

                  Working...
                  X