Using your own user table in WebApps: Difference between revisions
Creating |
Typo |
||
Line 33: | Line 33: | ||
##Replace the line "Set psUsername to (Trim(WebAppUser.FullName))" with "Set psUsername to (Trim({''YourUserTable''}.{''YourUserFullname''}))" // Optional - otherwise just remove the line | ##Replace the line "Set psUsername to (Trim(WebAppUser.FullName))" with "Set psUsername to (Trim({''YourUserTable''}.{''YourUserFullname''}))" // Optional - otherwise just remove the line | ||
##Replace the line "Set psLoginName to (Trim(WebAppUser.LoginName))" with "Set psLoginName to (Trim({''YourUserTable''}.{''YourIdColumn''})) | ##Replace the line "Set psLoginName to (Trim(WebAppUser.LoginName))" with "Set psLoginName to (Trim({''YourUserTable''}.{''YourIdColumn''})) | ||
##Replace the line: "Set piUserRights to WebAppUser.Rights" with "Set piUserRights to {''YourUserTable''}.{'' | ##Replace the line: "Set piUserRights to WebAppUser.Rights" with "Set piUserRights to {''YourUserTable''}.{''YourRightsColumn''} // Optional - if you don't have a rights column, remove the line. Note: if you use an ASCII column, rather than a numeric one for this, you will need to add a different property in the Construct_Object procedure of the class - something like "Property String psUserType" and "Set" that instead | ||
#Remove all the other methods from your sub-class (they are covered in cWebSessionManagerStandard) : | #Remove all the other methods from your sub-class (they are covered in cWebSessionManagerStandard) : | ||
##CreateSession | ##CreateSession |
Revision as of 14:48, 30 April 2021
In most cases when creating a WebApp for an existing (Windows) system, that system will already have a mechanism for checking user credentials (i.e. user-name and password) in existance. The Data Access supplied mechanism for WebApps uses its own tables for this and for session management within that. So how do we integrate the two?
Actually it is reasonably simple, but I'm going to go through it line-by-line, so it will seem like a lot, but it really isn't.
The instructions below assume that your system has a user table; that it has a userID column of some sort; that column is the primary (unique) key; and that column is the sole element of Index.1 on that table. (If that last is not the case, you will have to also modify the "Send Find of hoUserDD EQ Index.1" line in the Userlogin procedure in your sub-class to use the correct index.)
Text in {italics} should be replaced with the appropriate values for your own system.
Step 1. If you have not already done it, Create a WebApp Project in your workspace.
Step 2. From {DataFlexInstalledLocation}\Pkg:
- Copy cWebSessionManagerStandard.pkg (note: not cWebSessionManager.pkg) to your AppSrc directory, renaming it to cWebSessionManager{YourSystemName}.pkg
- Copy cWebAppUserDataDictionary.pkg and cWebAppSessionDataDictionary.pkg to your DDSrc directory (the former will not actually be used, but will be modified by the next step of the process, so best to copy it too)
Step 3. Change the relationship of WebAppSession to WebAppUser to point to your user table instead:
- The relationship needs to be on identically defined columns (same type and size). I don't think that we ought to impact the existing system when that can be avoided, so if a change is needed (and it usually will be) the change should be at the WebAppSession table end. Modify (in the Studio, right-click WebAppSession in the Table Explorer pane/tab, select "Edit Table" and make the required change to the LoginName column) that so that it matches the (unique) primary key (the user ID) of your current user table. (So if your current user table has a column - say, UserID - which is ASCII 10, modify WebAppSession.LoginName to be ASCII 10 from its original ASCII 20.)
- In the "Relationships" tab, delete the relationship to WebAppUser (the only one there) and add a replacement pointing to your user table, from LoginName on WebAppSession, to whatever the user ID column is on your user table.
Step 4. Modify your cWebSessionManager sub-class:
- Change the use statement: "Use cWebSessionManager.pkg" to "Use cWebSessionManagerStandard.pkg"
- Replace the use statement: replace "Use cWebAppUserDataDictionary.dd" with "Use c{YourUserTable}DataDictionary.dd"
- Change the classname: from "Class cWebSessionManagerStandard is a cWebSessionManager" to "Class cWebSessionManager{YourSystemName} is a cWebSessionManagerStandard" (so sub-classing cWebSessionManagerStandard)
- Change the user data dictionary instance: in the Construct_Object procedure change "Get Create (RefClass(cWebAppUserDataDictionary)) to hoUserDD" to "Get Create (RefClass(c{YourUserTable}DataDictionary)) to hoUserDD"
- Modify the UserLogin function:
- Replace the line: "Move sLoginName to WebAppUser.LoginName" with "Move sLoginName to {YourUserTable}.{YourIdCol}
- Replace the line: "If (Found and (Lowercase(sLoginName) = Lowercase(Trim(WebAppUser.LoginName)))) Begin" with "If (Found and (Lowercase(sLoginName) = Lowercase(Trim({YourUserTable}.{YourIdCol})))) Begin"
- Replace the line: "Get Field_Current_Value of hoUserDD Field WebAppUser.Password to sUserPassword" with "Get Field_Current_Value of hoUserDD Field {YourUserTable}.{YourPasswordCol} to sUserPassword"
- Replace the line: "Set Field_Changed_Value of hoUserDD Field WebAppUser.LastLogin to (CurrentDateTime())" with "Set Field_Changed_Value of hoUserDD Field {YourUserTable}.{YourLastLoginCol} to (CurrentDateTime())" // This one is optional. You may not have such a column (a date, by default) and if you do not wish to create one just remove the line
- Modify the UpdateSessionProperties function:
- Replace the line "Set psUsername to (Trim(WebAppUser.FullName))" with "Set psUsername to (Trim({YourUserTable}.{YourUserFullname}))" // Optional - otherwise just remove the line
- Replace the line "Set psLoginName to (Trim(WebAppUser.LoginName))" with "Set psLoginName to (Trim({YourUserTable}.{YourIdColumn}))
- Replace the line: "Set piUserRights to WebAppUser.Rights" with "Set piUserRights to {YourUserTable}.{YourRightsColumn} // Optional - if you don't have a rights column, remove the line. Note: if you use an ASCII column, rather than a numeric one for this, you will need to add a different property in the Construct_Object procedure of the class - something like "Property String psUserType" and "Set" that instead
- Remove all the other methods from your sub-class (they are covered in cWebSessionManagerStandard) :
- CreateSession
- ValidateSession
- IsLoggedIn
- ComparePasswords
- OnSessionPropertiesSet
- OnSessionPropertiesClear
- EndSession
Step 5. Modify SessionManager.wo to use your sub-class:
- Change: "Use cWebSessionManagerStandard.pkg" to "Use cWebSessionManager{YourSystemName}.pkg"
- Change: "Object oSessionManager is a cWebSessionManagerStandard" to "Object oSessionManager is a cWebSessionManager{YourSystemName}"
Now you should be good to go and users of your Windows app will/can also be users of your WebApp!