JSDO properties, methods, and events reference : afterLogin event
  

afterLogin event

Fires when the login( ) method on the current Session object completes execution after it was called asynchronously.
Applies to:progress.data.Session class
The following parameters appear in the signature of any event handler (callback) function (or functions) that you subscribe to this event:

Syntax

function ( login-session , result , error-object )
login-session
A reference to the Session object that fired the event.
result
A numeric constant that the login( ) method returns when called synchronously. Possible constants include:
*progress.data.Session.LOGIN_SUCCESS — JSDO login session started successfully.
*progress.data.Session.LOGIN_AUTHENTICATION_FAILURE — JSDO session login failed because of invalid user credentials.
*progress.data.Session.LOGIN_GENERAL_FAILURE — JSDO session login failed because of a non-authentication failure.
This value can also be returned if invalid user credentials triggered a login timeout according to the value of the login( ) method's parameter-object.iOSBasicAuthTimeout property.
For all other errors, this event returns an Error object reference as error-object. You can also return the result for the most recent login attempt on login-session by reading its loginResult property. For a more specific status code returned in the HTTP response, you can check the value of its loginHttpStatus property. For more detailed information about any response (successful or unsuccessful) returned from the Web server, you can also check the XMLHttpRequest object (XHR) returned by its lastSessionXHR property.
If error-object is not null, result will be null.
error-object
A reference to any Error object that might have been thrown as login-session processed the login( ) method response. This value can be null. If it is not null, result will be null.
Note: If this object is thrown because of a login timeout triggered according to the value of the login( ) method's parameter-object.iOSBasicAuthTimeout property, the message property of the error object is set to "login timeout expired".
Note: These callback parameters provide the same information that is available after a synchronous invocation of login( ).
Application code can subscribe a callback to this event by invoking the subscribe( ) method on a Session object.

Example

The following code fragment subscribes the function, onAfterLogin, to handle the afterLogin event fired on the session, empSession, after the login( ) method is called asynchronously. The event callback checks for either an expected return value, an invalid return value (as part of a test), or a thrown Error object with an unknown error (passed as errorObject to the callback), then assembles an appropriate message to display in an alert box:
var retValue;
empSession.subscribe('afterLogin', onAfterLogin);

retValue = empSession.login( {
serviceURI : "http://testmach:8980/SportsMobileApp",
userName : uname,
password : pw,
async : true } );
/* ( retValue is progress.data.Session.ASYNC_PENDING ) */

/* Invoked by empSession when it processes the login response from the web
application */
function onAfterLogin( pdsession, result, errorObject ) {
var msg;

if ( result === null ) {
msg = "Employee Login failed: Error attempting to call login()";
}
else if ( result === progress.data.Session.LOGIN_AUTHENTICATION_FAILURE ) {
msg = "Employee Login failed: Authentication error";
}
else if ( result === progress.data.Session.LOGIN_GENERAL_FAILURE ) {
msg = "Employee Login failed: Unspecified error";
}
else if ( result === progress.data.Session.LOGIN_SUCCESS ) {
msg = "Logged in successfully”;
}
else {
if (errorObject) {
msg = '\n' + errorObject.message;
}
msg = "TEST ERROR! UNEXPECTED login result: " + msg;
}
msg = msg +
"\nloginResult: " + pdsession.loginResult +
"\nloginHttpStatus: " + pdsession.loginHttpStatus +
"\nuserName: " + pdsession.userName +
"\nlastSessionXHR: " + pdsession.lastSessionXHR;

alert(msg);
}

See also:

lastSessionXHR property, login( ) method (Session class), loginHttpStatus property, subscribe( ) method (Session class)