Controller/Router

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Controller/Router

Postby Otto » Wed Nov 18, 2020 8:22 am

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  Expand view


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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Antonio Linares » Wed Nov 18, 2020 9:41 am

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
Antonio Linares
Site Admin
 
Posts: 41332
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Controller/Router

Postby Otto » Wed Nov 18, 2020 10:20 am

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Antonio Linares » Wed Nov 18, 2020 10:36 am

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
Antonio Linares
Site Admin
 
Posts: 41332
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Controller/Router

Postby Otto » Wed Nov 18, 2020 2:16 pm

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Otto » Wed Nov 18, 2020 6:39 pm

Dear Antonio,
I tried with this code:
Code: Select all  Expand view

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Antonio Linares » Thu Nov 19, 2020 3:51 pm

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
Antonio Linares
Site Admin
 
Posts: 41332
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Controller/Router

Postby Otto » Thu Nov 19, 2020 8:33 pm

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Antonio Linares » Fri Nov 20, 2020 7:50 am

Dear Otto,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41332
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Controller/Router

Postby Otto » Sun Nov 22, 2020 4:22 pm

Dear Antonio,
there is WINDOWS SERVER 2012 R2 installed.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm

Re: Controller/Router

Postby Otto » Sat Feb 12, 2022 7:24 pm

Dear Antonio,
I am on a WINDOWS server.
Should these functions work?
Best regards,
Otto


Apr 28 2021 18:57:35
NIL
NIL


Code: Select all  Expand view
function main

? ModBuildDate()

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6033
Joined: Fri Oct 07, 2005 7:07 pm


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 3 guests