Using your own user table in WebApps: Difference between revisions
Creating |
Hsymington (talk | contribs) m Formatting changes. |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
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. | 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 <u>not</u> the case, you will have to also modify the "Send Find of hoUserDD EQ Index.1" line in the | 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 <u>not</u> 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. | Text in {''italics''} should be replaced with the appropriate values for your own system. | ||
Line 11: | Line 11: | ||
====Step 2. From {''DataFlexInstalledLocation''}\Pkg:==== | ====Step 2. From {''DataFlexInstalledLocation''}\Pkg:==== | ||
# Copy cWebSessionManagerStandard.pkg (note: <u>not</u> cWebSessionManager.pkg) to your AppSrc directory, renaming it to cWebSessionManager{''YourSystemName''}.pkg | # Copy [https://docs.dataaccess.com/dataflexhelp/mergedProjects/VDFClassRef/cWebSessionManagerStandard.htm cWebSessionManagerStandard.pkg] (note: <u>not</u> 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) | # Copy [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcWebAppUserDataDictionary.htm&rhsearch=cWebAppUserDataDictionary.pkg&rhhlterm=cWebAppUserDataDictionary.pkg&rhsyns=%20 cWebAppUserDataDictionary.pkg] and [https://docs.dataaccess.com/dataflexhelp/index.htm#t=mergedProjects%2FVDFClassRef%2FcWebAppSessionDataDictionary.htm&rhsearch=cWebAppSessionDataDictionary&rhhlterm=cWebAppSessionDataDictionary&rhsyns=%20 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:==== | ====Step 3. Change the relationship of WebAppSession to WebAppUser to point to your user table instead:==== | ||
Line 21: | Line 21: | ||
====Step 4. Modify your cWebSessionManager sub-class:==== | ====Step 4. Modify your cWebSessionManager sub-class:==== | ||
#Change the use statement: "Use cWebSessionManager.pkg" to "Use cWebSessionManagerStandard.pkg" | #Change the use statement:<br /> "Use cWebSessionManager.pkg"<br /> to:<br /> "'''Use cWebSessionManagerStandard.pkg'''" | ||
#Replace the use statement: | #Replace the use statement:<br /> "Use cWebAppUserDataDictionary.dd"<br /> with: <br />"'''Use c{''YourUserTable''}DataDictionary.dd'''" | ||
#Change the classname: | #Change the classname:<br /> "Class cWebSessionManagerStandard is a cWebSessionManager" <br />to: <br /> "'''Class cWebSessionManager{''YourSystemName''} is a cWebSessionManagerStandard'''" (so sub-classing cWebSessionManagerStandard) | ||
#Change the user data dictionary instance: in the '''Construct_Object''' procedure | #Change the user data dictionary instance: in the '''Construct_Object''' procedure <br />"Get Create (RefClass(cWebAppUserDataDictionary)) to hoUserDD" <br />to: <br />"'''Get Create (RefClass(c{''YourUserTable''}DataDictionary)) to hoUserDD'''" | ||
#Modify the '''UserLogin''' function: | #Modify the '''UserLogin''' function: | ||
##Replace the line: "Move sLoginName to WebAppUser.LoginName" with "Move sLoginName to {''YourUserTable''}.{''YourIdCol''} | ##Replace the line: <br />"Move sLoginName to WebAppUser.LoginName" <br />with: <br />"'''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: <br />"If (Found and (Lowercase(sLoginName) = Lowercase(Trim(WebAppUser.LoginName)))) Begin" <br />with: <br />"'''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: <br />"Get Field_Current_Value of hoUserDD Field WebAppUser.Password to sUserPassword"<br /> with: <br />"'''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 | ##Optional. Replace the line: <br />"Set Field_Changed_Value of hoUserDD Field WebAppUser.LastLogin to (CurrentDateTime())"<br /> with:<br /> "'''Set Field_Changed_Value of hoUserDD Field {''YourUserTable''}.{''YourLastLoginCol''} to (CurrentDateTime())'''" // This one is optional because 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: | #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:<br /> "Set psUsername to (Trim(WebAppUser.FullName))"<br /> with:<br /> "'''Set psUsername to (Trim({''YourUserTable''}.{''YourUserFullname''}))'''" | ||
##Replace the line "Set psLoginName to (Trim(WebAppUser.LoginName))" with "Set psLoginName to (Trim({''YourUserTable''}.{''YourIdColumn''})) | ##Replace the line:<br /> "Set psLoginName to (Trim(WebAppUser.LoginName))"<br /> with: <br />"'''Set psLoginName to (Trim({''YourUserTable''}.{''YourIdColumn''}))'''" | ||
##Replace the line: "Set piUserRights to WebAppUser.Rights" with "Set piUserRights to {''YourUserTable''}.{'' | ##Optional - if you don't have a rights column, remove the line. Replace the line:<br /> "Set piUserRights to WebAppUser.Rights"<br /> with:<br /> "'''Set piUserRights to {''YourUserTable''}.{''YourRightsColumn''}'''" // '''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 its super-class cWebSessionManagerStandard): | ||
##CreateSession | ##CreateSession | ||
##ValidateSession | ##ValidateSession | ||
Line 45: | Line 45: | ||
====Step 5. Modify SessionManager.wo to use your sub-class:==== | ====Step 5. Modify SessionManager.wo to use your sub-class:==== | ||
#Change: "Use cWebSessionManagerStandard.pkg" to "Use cWebSessionManager{''YourSystemName''}.pkg" | #Change:<br /> "Use cWebSessionManagerStandard.pkg"<br /> to:<br /> "'''Use cWebSessionManager{''YourSystemName''}.pkg'''" | ||
#Change: "Object oSessionManager is a cWebSessionManagerStandard" to "Object oSessionManager is a cWebSessionManager{''YourSystemName''}" | #Change:<br /> "Object oSessionManager is a cWebSessionManagerStandard" <br />to:<br /> "'''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! | Now you should be good to go and users of your Windows app will/can also be users of your WebApp! | ||
[[Category: Web Applications]] |
Latest revision as of 10:42, 5 May 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:
"Use cWebAppUserDataDictionary.dd"
with:
"Use c{YourUserTable}DataDictionary.dd" - Change the classname:
"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
"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" - Optional. 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 because you may not have such a column (a date, by default) and if you do not wish to create one just remove the line.
- Replace the line:
- Modify the UpdateSessionProperties function:
- Optional - otherwise just remove the line. Replace the line:
"Set psUsername to (Trim(WebAppUser.FullName))"
with:
"Set psUsername to (Trim({YourUserTable}.{YourUserFullname}))" - Replace the line:
"Set psLoginName to (Trim(WebAppUser.LoginName))"
with:
"Set psLoginName to (Trim({YourUserTable}.{YourIdColumn}))" - Optional - if you don't have a rights column, remove the line. Replace the line:
"Set piUserRights to WebAppUser.Rights"
with:
"Set piUserRights to {YourUserTable}.{YourRightsColumn}" // 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
- Optional - otherwise just remove the line. Replace the line:
- Remove all the other methods from your sub-class (they are covered in its super-class 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!