Web Connect How To : Show Me the Code!

 LAFOX Home How URL Maps to Code  LAFOX Design Oveview  Framework Extensions 
*Login.prg #INCLUDE WCONNECT.H *************************************************************** ** rbPage is our own custom class ** It represents an HTML page ** ** It is called from rbProcess (our Web-Connect Process Class) ** ** Look inside rbProcess.prg for comments as to ** how we map a URL to a specific Class and Method *************************************************************** DEFINE CLASS Login AS rbPage ********************************************************************** ** Page() - PUBLIC - ** show a blank login page for user input ********************************************************************** FUNCTION PAGE STORE .NULL. TO This.oData && ALWAYS init ** Blank Data Object This.oData = THIS.DataObject("Member","MemberID",[-1]) && Blank Data Object ** LoginFragment - with standard menu THIS.Content = THIS.MergeToString("LoginFragment.htm") THIS.PageTitle = "Login" THIS.Merge("TemplatePage.htm") ENDFUNC &&Page ********************************************************************** ** Submit() - PUBLIC - ** User submits login page ********************************************************************** PROCEDURE Submit() ** Read the form This.oData = THIS.ReadForm("Member","MemberID") ** Read which button the user clicked IF UPPER(REQUEST.FORM("btnSubmit")) == UPPER([EMail My Password to Me]) THIS.MailPassword ELSE THIS.Login ENDIF ENDPROC && Submit ************************************************************* ** Helper Functions Below ************************************************************* ********************************************************** ** Login() ********************************************************** HIDDEN FUNCTION Login LOCAL lcUserLevel, lcMemberID STORE [] TO lcUserLevel, lcMemberID ** GetUserLevel - Not Found / User / Admin lcUserLevel = THIS.GetUserLevel(This.oData.eMail, This.oData.PASSWORD, @lcMemberID) IF (lcUserLevel == "NOT FOUND") OR (lcUserLevel == "BAD PASSWORD") ** Show Login.Page with error message THIS.AddError(lcUserLevel + "<br>"+ ; [Try "Email My Password" BUTTON<br>]+; [OR CLICK ON "Email to WebMaster" LINK below]) THIS.Content = THIS.MergeToString("LoginFragment.htm") THIS.PageTitle = "Login Again" THIS.Merge("TemplatePage.htm") ELSE ** Login was successful ** so save the user info ** See Persist.prg for definition and rbProcess.prg for creation SessionVars.Globals.SET("UserType", lcUserLevel) SessionVars.Globals.SET("MemberID", lcMemberID) THIS.Redirect("LoggedIn.Page") ENDIF ENDFUNC && Login ********************************************************** ** MailPassword() ********************************************************** HIDDEN FUNCTION MailPassword LOCAL lcPassword, lcMessage STORE [] TO lcPassword, lcMessage IF THIS.GetPasswordFromEmail(This.oData.eMail, @lcPassword) ** Email password to user lcMessage = [Your Password is ] + lcPassword + CRLF+; [You can CHANGE PASSWORD BY choosing "Edit My Profile" AFTER You are logged IN.] SERVER.SendMail("mail.bricksoftware.com",; Site.SiteName + [ Automated Response], ; "WebMaster@"+Site.SiteName+[.org] ,; This.oData.eMail, ; [], ; Site.SiteName+ [ Password] , ; lcMessage) ** Web Page - let them know we sent it THIS.WaitWindow("Password Mailed to You!<br>"+ ; [You can CHANGE PASSWORD BY choosing "Edit My Password" AFTER You are logged IN.],; "/Home.Page.fox?SessionID=_71P0O15YP") ELSE ** Show Login.Page again with error message THIS.AddError("Sorry!<br>Email not found<br>Please try again<br>or contact WebMaster") THIS.Content = THIS.MergeToString("LoginFragment.htm") THIS.PageTitle = "Login" THIS.Merge("TemplatePage.htm") ENDIF ENDFUNC && Login ********************************************************* ** GetUserLevel() ** tcMemberID passed by reference ** Returns UserLevel = "Not Found" or "User" or "Admin" ********************************************************* HIDDEN FUNCTION GetUserLevel(tcEmail, tcPassword, tcMemberID) AS STRING ** Open the table THIS.OpenAndSelect("Member") ** Normalize the strings for exact matches tcEmail = UPPER(PADR(tcEmail,LEN(Member.eMail))) tcPassword = UPPER(PADR(tcPassword,LEN(Member.PASSWORD))) ** locate for Email and Password LOCATE FOR UPPER(eMail) = tcEmail IF FOUND() tcMemberID = MemberID ENDIF DO CASE CASE UPPER(eMail) = tcEmail AND (NOT (UPPER(PASSWORD) = tcPassword)) RETURN "BAD PASSWORD" ** Case found and userlevel Blank CASE FOUND() AND EMPTY(MemberType) RETURN "USER" ** Case found and userlevel has value CASE FOUND() AND NOT EMPTY(MemberType) RETURN UPPER(ALLTRIM(MemberType)) OTHERWISE &&not found() RETURN "NOT FOUND" ENDCASE ENDFUNC && GetUserLevel ************************************************************************ ** GetPasswordFromEmail() ** If the email is in our database ** fill in the by-reference param tcPassword and return .T. ** Else ** return .F. = Email not found ************************************************************************ HIDDEN FUNCTION GetPasswordFromEmail(tcEmail, tcPassword) ** Open the table THIS.OpenAndSelect("Member") ** Normalize the strings for exact matches tcEmail = UPPER(PADR(tcEmail,LEN(Member.eMail))) ** locate for Email and Password LOCATE FOR UPPER(eMail) = tcEmail IF FOUND() AND NOT EMPTY(tcEmail) tcPassword = PASSWORD RETURN .T. ELSE RETURN .F. ENDIF ENDFUNC && GetPasswordFromEmail ENDDEFINE && Login
csCodeParser v0.9 stats: 176 lines in 0.01 seconds.