Recent

Author Topic: Writing Web application using CGI's/Apache modules  (Read 8301 times)

sandeep_c24

  • Full Member
  • ***
  • Posts: 114
Writing Web application using CGI's/Apache modules
« on: February 28, 2009, 02:42:17 am »
I have a cgi app where I have added a "Login" action which returns a form with action "DoLogin". If the user login is ok I want "DoLogin" to redirect to "Welcome" action and if not return to output of "Login" action. How do I do this?

Sandeep

bobo

  • Full Member
  • ***
  • Posts: 171
Re: Writing Web application using CGI's/Apache modules
« Reply #1 on: February 28, 2009, 04:43:09 am »
The best way is to have 2 html templates and to return with the proper content based on the login info passed.
You do not need 2 actions for this, only one:

procedure TFPWebModule1.DoLoginRequest(Sender: TObject; ARequest: TRequest;
  AResponse: TResponse; var Handled: Boolean);
begin     //Template:TFPTemplate is a property of the web Action
  Handled := true;
  Template.AllowTagParams := true;
  Template.FileName := 'pathtotemplate/login.html';
  Template.OnReplaceTag := @loginscreenlReplaceTags;

  if There-Are-No-Login-Name-And-Password-In-The-Passed-ContentFields then
  begin//just show the initial empty login-form screen
    AResponse.Content := Template.GetContent;
    Exit;
  end;
{
... decide if login attempt successful
}
  if LoginSuccesful then
  begin//use the welcome screen template
    Template.FileName := 'pathtotemplate/welcome.html'
    Template.OnReplaceTag := @welcomescreenlReplaceTags;
  end;
  AResponse.Content := Template.GetContent;
end;

Of course, you need both welcomescreenlReplaceTags and loginscreenlReplaceTags to be there to handle the template tags if there are any.
Inside loginscreenlReplaceTags for example you can put a message out to the form on unsuccesful login, and maybe fill out the login name field when returning the form, so it does not have to be filled out again by the visitor. Etc.

sandeep_c24

  • Full Member
  • ***
  • Posts: 114
Re: Writing Web application using CGI's/Apache modules
« Reply #2 on: March 01, 2009, 09:55:39 am »
For some Actions I want the user to be logged in, if the user is not logged in I want the Login action to be executed. How do I do this?

Sandeep

bobo

  • Full Member
  • ***
  • Posts: 171
Re: Writing Web application using CGI's/Apache modules
« Reply #3 on: March 03, 2009, 12:48:06 am »
You need to use sessions to track who is logged in and who is not.
You can use cookies for example and update a table on the server about the status of the sessions of the visitors.

There are session objects available in the fpweb package too, but I did not use them yet. I'll create some example projects for sessions and post it for inclusion into the fcl-web package.
« Last Edit: March 03, 2009, 12:51:19 am by bobo »

sandeep_c24

  • Full Member
  • ***
  • Posts: 114
Re: Writing Web application using CGI's/Apache modules
« Reply #4 on: March 03, 2009, 01:25:00 am »
Hi bobo

I am using Session and it looks they work fine. What I want to do now is to redirect the request to Login action if the user pastes a url and the user has logged out/session has timed out.

Sandeep

bobo

  • Full Member
  • ***
  • Posts: 171
Re: Writing Web application using CGI's/Apache modules
« Reply #5 on: March 03, 2009, 06:40:28 am »
Well, the SendRedirect(const TargetURL:String) function will only be available if
http://bugs.freepascal.org/view.php?id=13254
is applied to the SVN trunk. It contains a bunch of bug fixes and additions.

Until then you just have to return with the login page content yourself instead of redirecting. It is faster to do that anyway.

 

TinyPortal © 2005-2018