Writing Web application using CGI's/Apache modules lazarus / 1-Linux ---------------------------------------------------------------------- sandeep_c24 · 2009-02-28 01:42 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 · 2009-02-28 03:43 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 · 2009-03-01 08:55 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 · 2009-03-02 23:48 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. ---------------------------------------------------------------------- sandeep_c24 · 2009-03-03 00:25 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 · 2009-03-03 05:40 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.