| Home | Previous Lesson: Customizing the Application Manager Next Lesson: Multiple Login Attempts Functionality |
In order to provide database login functionality in your application using PFC services, you need to code at couple of places. The first one is in your application manager's pfc_open event.
// Object: n_cst_pms_AppManager
// Event: pfc_open
int li_rc
this.of_Splash(1)
Idle(300)
Yield()
open(w_mdi_frame)
li_rc = gnv_app.of_LogonDlg()
IF li_rc <> 0 AND li_rc <> 1 THEN
MessageBox("Error", "Logon failed!" + "~r" + &
"Error Message: " + sqlca.sqlErrText, Exclamation!,OK!,1)
halt close
elseif li_rc = 0 then
halt close
end if
In the above code, we are basically displaying a splash window that splashes your application's or company's logo for the specified seconds. Then we are opening the MDI Frame window and calling the of_LogonDlg function.
of_LogonDlg() reads the previously used login from registry/INI file to display it in the login window. If userid is not available, it instantiates platform services and gets the current logged in (on to the operating system) user name. Note that the login name displayed in the logon window is read from the userid string value of registry_key_you_supplied + "\logon" registry key. Then, this function opens the login window with login object as parameter.
w_login's open event validates Message object for logon object and displays user id, password, picture, application name, etc. and focus appropriate object depending on the values supplied in logon object. When the user clicks on the OK CommandButton in the login window, pfc_logon event at the application manager will be called (See in the picture).
// Object: n_cst_pms_AppManager
// Event: pfc_logon
if of_IsRegistryAvailable() then
sqlca.of_Init (of_GetUserKey())
else
if sqlca.of_Init (is_userinifile, "Database") = -1 then
MessageBox(iapp_object.DisplayName, + &
"Initialization failed from file " + is_userinifile)
halt
end if
end if
SQLCA.of_SetUser(as_userid, as_password)
IF SQLCA.of_Connect() = -1 THEN
Return -1
ELSE
gnv_app.of_SetUserID(as_userid)
Return 1
END IF
The pfc_logon event gets user id and password as arguments. It is our responsibility to populate SQLCA and connect to the database and send appropriate return code. of_Init(), an overloaded function, allows you to read database specific information from registry/profile file and loads the SQLCA object.
Then call SQLCA.of_setuser() to over write the user id and password with the one supplied by the user. Please note that, this function sets UID and PWD options in the ConnectString for DBPARM parameter. This doesn't set LogID/LogPass OR UserID/DBPass attributes of transaction object; The value specified in the ConnectString takes precedence than other attributes in the transaction object.
To connect to the database, either call CONNECT USING SQLCA; or call SQLCA.of_Connect(). Calling any one of them is ok, unless you are using SQLSpy service which has hooks from of_Connect().
During the login failures, you will see "The password is incorrect." error message irrespective of the actual error message. This is because the message is hard-coded in pfc_default event in pfc_w_logon window. You may want to overwrite this event in your extension level by copying and pasting all that code to your extension object and changing it to SQLCA.sqlErrText.
| Home | Previous Lesson: Customizing the Application Manager Next Lesson: Multiple Login Attempts Functionality |