Some sample code is provided to help manage account logons to allow multiple requests to be serviced in this environment. When you download and install the Host Simulator and samples, a file called UserIdPassword.exe is installed in the Library subdirectory of your Host Publisher installation directory. Run UserIdPassword.exe to extract the sample code. See the file Readme.html for further installation instructions.
The sample code is straightforward. It is not supported, but the source code is provided so that you can tailor it to your needs.
Code is provided to get a userid and its password, release a userid, and to release all the userids (to clean up, if necessary).
The technique provided uses a database to keep track of the accounts. Using Dynascript on a Web page, you can reserve an account to use, pass it to an integration object, and release it.
Because the page server only evaluates Dynascript after all the other DYNA tags in a Web page, it is not possible to reserve a userid using Dynascript, use it in other DYNA tags, and release the userid again. There are two other approaches that work.
Two Web pages can be used. Dynascript on the first page reserves a userid. The userid is passed to a second page, where it is used and released. The drawback to this approach is that the user must follow a link to the second page. If the link is not followed, the userid remains reserved indefinitely. A second drawback is that if the user bookmarks the second page and then revisits it, they attempt to use a userid they have not reserved.
A better approach is to put most or all of the Web page inside Dynascript. You can use Dynascript to reserve a userid, invoke a host access integration object, and release the userid. This minimizes the chances of losing userids.
Before continuing, you might want to review the Scripting section on use of Dynascript in Web pages.
Warning: This technique fails if the page is scoped to client; be sure it is scoped to page (the default setting). (If the page is scoped to client, the integration object might remain logged in with the userid even after the script has returned the userid to the databaose.)
FieldName | FieldType(Size) | Comment |
---|---|---|
userid | text(50) | KEY |
password | text(50) | |
available | text(1) | "1" = available "0" = in use |
sortfield | autonumber | Used to sort the IDs during the select |
A Java integration object uses JDBC to access the database. The Java methods provided are:
Script | Comments |
---|---|
<DYNASCRIPT language=JavaScript> | Begin script |
oUserIDManager = IObjects.Get("useridmanager"); | Create an integration object to reference the useridmanager. |
vUserID = oUserIDManager.GetItem("getNextUserID"); vPassword = oUserIDManager.GetItem("getNextPassword"); | Get the user ID and the corresponding password. |
Environment.PARAMS.SetProp("userid",vUserID); Environment.PARAMS.SetProp("password",vPassword); | Put the user ID and password into Web parameters so the host access integration object can use them. |
var oDate = IObjects.Get("hostdate"); Document.Writeln("The date is: " + oDate.GetItem("date"); | Create a host access integration object, get some data from it, and output it as part of the Web page. |
oUserIDManager.GetItem("releaseUserID"); | Release the user ID. |
</DYNASCRIPT> | End the DYNAscript. |