Return-Path: Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: (qmail 67905 invoked from network); 14 Jun 2005 19:28:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 14 Jun 2005 19:28:57 -0000 Received: (qmail 3746 invoked by uid 500); 14 Jun 2005 19:28:47 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 3726 invoked by uid 500); 14 Jun 2005 19:28:47 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 3686 invoked by uid 99); 14 Jun 2005 19:28:46 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FORGED_RCVD_HELO,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of jonnybecker@gmx.net designates 213.165.64.20 as permitted sender) Received: from mail.gmx.de (HELO mail.gmx.net) (213.165.64.20) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 14 Jun 2005 12:28:40 -0700 Received: (qmail invoked by alias); 14 Jun 2005 19:21:50 -0000 Received: from p549A5B9D.dip.t-dialin.net (EHLO [192.168.2.105]) [84.154.91.157] by mail.gmx.net (mp033) with SMTP; 14 Jun 2005 21:21:50 +0200 X-Authenticated: #22981904 Message-ID: <42AF2E46.9000808@gmx.net> Date: Tue, 14 Jun 2005 21:21:42 +0200 From: Johannes Becker User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: users@cocoon.apache.org Subject: Re: Login and CForms - How to handle in FlowScript? References: <4283567E.8060902@gmx.net> <1115904243.4891.0.camel@trussardi.softsky.com.ua> <42AEB560.8010907@gmx.net> <7945bc0cdcd41a11fc9144cb426aba3e@wrinkledog.com> In-Reply-To: <7945bc0cdcd41a11fc9144cb426aba3e@wrinkledog.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Y-GMX-Trusted: 0 X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This helped a lot and saved the day. Thanks a lot for your help. Jonny Mark Lundquist wrote: > Hi Jonny, > > On Jun 14, 2005, at 3:45 AM, Johannes Becker wrote: > >> Hi, >> >> I have a CForm (Definiton + Template) and a login-function in flow. >> Now I want to combine these two. >> >> function loginpage() { >> var loginForm = new Form("forms/LoginForm_d.xml"); >> loginForm.showForm("form/LoginForm"); >> } >> >> function login() { >> var message = false; >> var username = cocoon.request.get("username"); >> var password = cocoon.request.get("password"); >> >> account = getStore().readAccount(username, password);; >> if (account == null) { >> return message; >> } else { >> message = "true"; >> return message; } >> } >> } >> >> Is it possible (and wise) to change the loginpage()-function like this: >> >> function loginpage() { >> while(true){ >> var loginForm = new Form("forms/LoginForm_d.xml"); >> loginForm.showForm("form/LoginForm"); >> var loggedin = login(); >> if(loggedin == "true") break; >> } >> >> Since this approach doesn't seem quite right and efficient to me: > > > Yeah, you're right... it's not quite right :-) > > First some random observations: > > - You don't have to call the Form() constructor every time through > your loop. You only build the form model once, and you can display it > and accept submissions many times with the same Form object. > > - The style in CForms is to let the framework deal with the form > parameters... you get the data by interrogating the widgets. So lose > the calls to cocoon.request.get(), and ask the widgets for their > values instead (see example below). Also, I think it's bad form > (pardon the pun) to be displaying a form in one bit of flowscript, and > handling the parameters from the form submission in another piece of > flowscript. Part of the reason flowscript exists is so that you don't > have to do like in the "page scripting" mentality :-) > > - returning a string "true" is surely not the best? Booleans work > just fine in flowscript :-). > > - How does your application know to call loginpage()? You need to > keep track of whether the session user is logged in, and I don't see > that anywhere in your code... > > - You probably want to display some kind of message on an unsuccessful > login attempt? > > > I've done "authentication 'lite'", i.e. using flowscript only, w/o the > auth-fw, and you can do it more or less something like this: > > Suppose you have a flowscript function like this, that does something > you want protected by the login mechanism: > > function showStuff() { > getLoggedInUser(); // make sure the user is logged > in... > > . > . // whatever > . > } > > getLoggedInUser() is a function that doesn't return until the user has > successfully authenticated. So now we need: > > var currentUser = null; // note, global > flowscript variables are attached to the session > > function getLoggedInUser() { > if (currentUser == null) { > currentUser = login(); > } > } > > > function login() { > var loginForm = new Form("forms/LoginForm_d.xml"); > var model = loginForm.getModel(); > var loginUser = null; > var invalidLogin = false; > > while (loginUser == null) { > loginForm.showForm( > "form/LoginForm", > { > invalidLogin: invalidLogin > } > ); > loginUser = getStore().readAccount (model.username, > model.password); > invalidLogin = true; > } > return loginUser; > } > > In your LoginForm template, use the JXTemplate language to > conditionally display an error message based on the invalidLogin > variable passed in from flowscript... something like > > >

> Incorrect login ID and/or password. >

>
> > I think that's about all there is to it. Note, the above code sample > is written for the 'v1' flowscript forms API because that's what you > should probably be using. I've been using the 'v2' API for a long > time so my 'v1' is a little rusty... somebody else might be able to > improve the code in my example or correct it if need be :-) > > HTH, > �ml� > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org > For additional commands, e-mail: users-help@cocoon.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org For additional commands, e-mail: users-help@cocoon.apache.org