login( ) method (JSDOSession class)
- Last Updated: April 9, 2019
- 6 minute read
- OpenEdge
- Version 13.0
- Documentation
getSession( ) method.Starts a JSDO login session in a web
application for the current JSDOSession object by
sending an HTTP request with specified user credentials to the web application URI
specified in the object's constructor.
This method throws an error if the method arguments are invalid or if the underlying communication layer throws an error.
On a successful login, the JSDOSession
object sets its connected property to true. If the login fails, the object leaves its connected property set to false.
This method is always executed asynchronously and returns results in callbacks that you register using methods of a Promise object returned as the method value.
authenticationModel configuration property in the constructor of
the JSDOSession object correctly (see the notes on
authentication models).JSDOSession object, you can create a new, initialized
JSDOSession using the progress.data.getSession( ) stand-alone function. In one call, this function
instantiates the object, invokes its login( ) method with
specified credentials, then invokes its addCatalog( )
method to load a specified Data Service Catalog. For more information, see the getSession( ) stand-alone function description.Return type: jQuery Promise
Applies to: progress.data.JSDOSession class
Syntax
|
- username
- A
stringexpression containing a user ID for the method to send to the web server for authentication.Note: TheuserNameproperty of theJSDOSessionobject returns the most recent value passed to this method for the currentJSDOSessionobject. - password
- A
stringexpression containing a password for the method to send to the web server to authenticate the specified user. - parameter-object
- An object that contains the following optional property:
iOSBasicAuthTimeout— Anumberthat specifies the time, in milliseconds, that thelogin( )method waits for a response before returning an error. This error might mean that the user entered invalid credentials. If you set this value to zero (0), no timeout is set, andlogin( )can wait indefinitely before returning an error. If you do not set theiOSBasicAuthTimeoutproperty,login( )uses 4000 (4 seconds) as the default value.Note: Any non-zero timeout value (default or otherwise) for this parameter-object property operates only under certain conditions. Otherwise, any setting of this property has no effect. For more information, see the notes of the progress.data.JSDOSession class description.
login( ) method on the progress.data.Session class relies on the class constructor to
specify the web application URI and always uses the default web resource, /static/home.html, as the login target.Promise method signatures
jQuery Promise objects define methods that register a callback function
with a specific signature. The callback signatures depend on the method that returns the
Promise. Following are the signatures of callbacks registered by methods in any Promise
object that login( ) returns:
Syntax:
|
- promise
- A reference to the Promise object that is returned as the value of the
login( )method. For more information on Promises, see the notes on Promises in the description of the progress.data.JSDOSession class. - session
- A reference to the
JSDOSessionobject on whichlogin( )was called. - result
- A constant indicating the overall result of the call that can have
one of the following values:
progress.data.Session.AUTHENTICATION_SUCCESS— The JSDO login session started successfully. You can use JSDOs to access any Data Object Services supported by the web application to which theJSDOSessionobject has logged in.progress.data.Session.AUTHENTICATION_FAILURE— JSDO login failed because of invalid user credentials (username or password).progress.data.Session.GENERAL_FAILURE— JSDO login failed because of a non-authentication failure.Note: This value can also be returned if invalid user credentials triggered a login timeout according to the value of the parameter-object.iOSBasicAuthTimeoutproperty.
Note: It is not always necessary to test the value of result in a Promise method callback for thelogin( )method, especially if the callback is registered usingpromise.done( ), where the callback always executes with the same value (progress.data.Session.AUTHENTICATION_SUCCESS). - info
- A JavaScript object that can have the following properties:
errorObject— Any error object thrown as a result of sending a login request to the web server.Note: If this object is thrown because of a login timeout triggered according to the value of the parameter-object.iOSBasicAuthTimeoutproperty, themessageproperty of the error object is set to"login timeout expired".xhr— A reference to the XMLHttpRequest object sent to the web server to start a JSDO login session.
You can also return the result of the most recent login attempt on the
current JSDOSession object by reading its loginResult property. For a more specific status code returned in
the HTTP response, you can also check the value of the loginHttpStatus property.
JSDOSession object. The login will use the same
serviceURI and authenticationModel settings originally passed to the constructor, but you must
pass any required credentials each time login( ) is
called.General web server interaction
The general web server interaction with and response to this method depends
on the authentication model that the web server uses and how resources are accessed and
protected. You configure the authentication model for each web application deployed to the
Apache Tomcat and specify both the web application URI and its corresponding authentication
model to the JSDOSession object constructor. For more
information on the authentication models that a JSDOSession object supports, see the description of the constructor for the
progress.data.JSDOSession class.
For more information on these authentication models and how to configure them for a web application, see the sections on configuring web server authentication models in the server documentation for your Data Object Service.
login( ) call occurs, Progress recommends (in some cases
requires) that the mobile or web app pass the credentials as parameters to the login( ) method. In addition, you must correctly pass the value
of the authenticationModel configuration property to the
JSDOSession object's constructor. Coding the mobile or
web app in this way ensures that the proper credentials are submitted to the server and
promotes a favorable user experience.Example
The following code fragment calls the login( ) method on the JSDOsession object, empSession. This example uses the callbacks registered by the
Promise done( ) and fail( ) methods to check the result of
the call along with any error object thrown as a result of the request, then assembles an
appropriate message to display in an alert box. It also uses a
try-catch block in case the login( )
method throws an error object instead of sending the request to the server:
|
See also:
addCatalog( ) method (JSDOSession class), authenticationModel property (JSDOSession class), connected property, getSession( ) stand-alone function, loginHttpStatus property, loginResult property, logout( ) method (JSDOSession class), offline event, online event, serviceURI property, userName property