Web Connection
Global Login for my App Code Fail
Hi Rick, The complete code I am using to Create a Global Login for my App is as below :
*********
FUNCTION Login()
CLOSE TABLES
IF !USED("C:\wconnect\usersecurity")
USE C:\wconnect\usersecurity IN 0 ALIAS usersecurity
ENDIF
pcErrorMessage = ""
IF Request.IsPostback()
pcUsername = Request.Form("WebLogin_txtUsername")
pcPassword = Request.Form("WebLogin_txtPassword")
*!* SELECT usersecurity
IF SEEK(pcUsername,'usersecurity','lusername')
cPw = ALLTRIM(usersecurity.password)
IF pcPassword = cpw
this.customerlist()
RETURN .T.
endif
else
IF this.Authenticate("ANY",@pcErrorMessage)
Response.Redirect("default.htm")
ENDIF
endif
RETURN
ENDIF
THIS.OnShowAuthenticationForm()
ENDFUNC
FUNCTION Logout()
this.Authenticate("Logout")
Response.Redirect("default.htm")
ENDFUNC
FUNCTION OnShowAuthenticationForm(lcUsername, lcUserpassword,lcErrorMsg)
pcUsername = lcUsername
pcPassword = ""
pcRedirectUrl = ""
pcErrorMessage = lcErrorMsg
pcDisplayMessage = "No account? No problem - <a href='Profile.ttk'>Create one</a>"
IF EMPTY(pcUsername)
pcUsername = ""
ENDIF
Response.ExpandScript("C:\webconnectionprojects\webdemo3\web\views\_login.wcs")
ENDFUNC
FUNCTION OnAuthenticated()
this.cAuthenticatedUserName = Session.GetSessionVar("AuthenticatedUserName")
this.nAuthenticatedUserPk = VAL(Session.GetSessionVar("AuthenticatedUserPk"))
RETURN .T.
ENDFUNC
FUNCTION OnAuthenticateUser(lcUserName,lcPassword,lcErrorMsg)
*** THIS IS THE DEFAULT IMPLEMENTATION
*** To override behavior override this method
IF EMPTY(lcUserName)
lcUserName = ""
ENDIF
IF EMPTY(lcPassword)
lcPassword = ""
ENDIF
this.oUserSecurity = CREATEOBJECT(this.cAuthenticationUserSecurityClass)
*** Default implementation is not case sensitive
IF !this.oUserSecurity.Authenticate(LOWER(lcUserName),LOWER(lcPassword))
this.cAuthenticatedUser = ""
this.cAuthenticatedUserName = ""
this.nAuthenticatedUserPk = -1
lcErrorMsg = this.oUserSecurity.cErrorMsg
RETURN .F.
*** Set lcErrorMsg to pass back via REF parm
ENDIF
&&&&&&&This is where the code is BREAKING&&&&&&&&&&&&
this.cAuthenticatedUser = this.oUserSecurity.oUser.UserName
this.cAuthenticatedName = this.oUserSecurity.oUser.FullName
this.nAuthenticatedUserPk = this.oUserSecurity.oUser.PK
Session.SetSessionVar(this.cAuthenticationUserSecurityKey,lcUsername)
Session.SetSessionVar("AuthenticatedUserName",this.cAuthenticatedUserName)
Session.SetSessionVar("AuthenticatedUserPk", this.nAuthenticatedUserPk)
RETURN .T.
ENDFUNC
What exactly is failing?
If you're getting a missing property error you need to add the propery in question. nAuthenticatedUserPk
is a custom property that is tracked by the application and it needs to be added to the class (if you want to keep track of it).
+++ Rick ---