Page 1 of 1

Controller/Router

Posted: Wed Nov 18, 2020 8:22 am
by Otto
Dear Antonio,
may I ask what the reason is that in GENESIS
these POST routes are inside CONTROLLER() and not router() function.


do case
case AP_Method() == "GET"
AP_RPuts( View( "default" ) )

case AP_Method() == "POST"
do case
case cAction == "save"
? "post save"
Save()

case cRequest == "login"
Login()
endcase
endcase



Best regards,

Otto

Code: Select all


function Controller( cRequest )

   local aRequest

   if ":" $ cRequest
      aRequest = hb_aTokens( cRequest, ":" )
      cRequest = aRequest[ 1 ]
      cAction  = If( Len( aRequest ) > 1, aRequest[ 2 ], "browse" )
      cParam1  = If( Len( aRequest ) > 2, aRequest[ 3 ], "" )
      cParam2  = If( Len( aRequest ) > 3, aRequest[ 4 ], "" )
      nVal1    = Val( cParam1 )
      nVal2    = Val( cParam2 )
   endif    

   if cRequest == "logout"
      AP_HeadersOutSet( "Set-Cookie", "genesis=" )
      cRequest = "login"
      cUserName = "guest"
   else   
      if ! hb_HhasKey( GetCookies(), "genesis" )
         cRequest = "login"
      else
         if cUserName != "guest"
            if cRequest == "login"
               cRequest = "home"
            endif 
         else
            cRequest = "login"
         endif
      endif              
   endif      

   hb_default( @cAction, "browse" )

   if cAction $ "add,browse" 
      if nVal1 == 0
         nVal1 = 20
      endif  
   endif   

   cContent = If( Empty( cRequest ), "home",;
       If( cRequest $ "login,logout,home,controllers,logs,menus,routes,database,users,settings,tasks,views,weblinks",;
           cRequest, "home" ) )

   do case   
      case AP_Method() == "GET"
         AP_RPuts( View( "default" ) )

      case AP_Method() == "POST"
         do case
            case cAction == "save"
               ? "post save"
                 Save()

            case cRequest == "login"
                 Login() 
         endcase 
   endcase   

return nil

//----------------------------------------------------------------------------//

function Router()

   local cRoute := "home"

   if GetContent() != "home"
      if GetContent() == "login"
         cRoute = "login"
      else         
         if GetAction() == "edit"
            cRoute = "edit"
         elseif GetAction() == "exec"
            cRoute = "exec"
         else      
            cRoute = "browse"
         endif
      endif   
   endif      

return View( cRoute )    

//----------------------------------------------------------------------------//

 

Re: Controller/Router

Posted: Wed Nov 18, 2020 9:41 am
by Antonio Linares
Dear Otto,

genesis was my first attempt to build a simple web ERP and by that time my analisys was not as accurated as it is today :-)

In our more recent mod_harbour developments the functions Controller() and Router() are joined together

Re: Controller/Router

Posted: Wed Nov 18, 2020 10:20 am
by Otto
Dear Antonio,

Many thanks. Do you have an example? This part is very important and I would so much prefer if I could use your code and design.

How do you suggest authentication?

Do you think I should offer 2 possibilities: chookies and sessions.

May I also ask if you would be so kind as to insert MREAD/MWRITE to mod harbour.

Best regards,
Otto

Re: Controller/Router

Posted: Wed Nov 18, 2020 10:36 am
by Antonio Linares
Dear Otto,

We only use mod_harbour sessions now

functions MRead() and MWrite() are part of mod_harbour already

I am going to prepare an example :-)

Re: Controller/Router

Posted: Wed Nov 18, 2020 2:16 pm
by Otto
Dear Antonio,
Thank you so much.
I make an update immediately.
Best regards,
Otto

Re: Controller/Router

Posted: Wed Nov 18, 2020 6:39 pm
by Otto
Dear Antonio,
I tried with this code:

Code: Select all

function main
MWrite( "pwd", "my password" ) // memory write
? MRead( "pwd" ) // memory read
//from other browser tab or another user:
? MRead( "pwd" )
//(There is also a new MErase( "pwd" ) but it is not working fine yet
TEMPLATE
ENDTEXT
return 
 
But I get NIL as response.
Best regards,
Otto

Re: Controller/Router

Posted: Thu Nov 19, 2020 3:51 pm
by Antonio Linares
Dear Otto,

Here it is working fine:
https://fivetechsoft.github.io/snippets?20201119155000

Please add this line and let me know what version you get:
? ModBuildDate()

Re: Controller/Router

Posted: Thu Nov 19, 2020 8:33 pm
by Otto
Dear Antonio,
here shows:
Oct 21 2020 11:11:03
NIL
NIL.

Best regards,
Otto

Re: Controller/Router

Posted: Fri Nov 20, 2020 7:50 am
by Antonio Linares
Dear Otto,

what Windows version is running on the server ?

Re: Controller/Router

Posted: Sun Nov 22, 2020 4:22 pm
by Otto
Dear Antonio,
there is WINDOWS SERVER 2012 R2 installed.
Best regards,
Otto