Controller/Router

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Controller/Router

Post 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 )    

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

 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Controller/Router

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Controller/Router

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Controller/Router

Post 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 :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Controller/Router

Post by Otto »

Dear Antonio,
Thank you so much.
I make an update immediately.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Controller/Router

Post 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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Controller/Router

Post 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()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Controller/Router

Post by Otto »

Dear Antonio,
here shows:
Oct 21 2020 11:11:03
NIL
NIL.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Controller/Router

Post by Antonio Linares »

Dear Otto,

what Windows version is running on the server ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Controller/Router

Post by Otto »

Dear Antonio,
there is WINDOWS SERVER 2012 R2 installed.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
Post Reply