I was thinking that maybe an MVC approach would work better, so I did a
search and found this http://www.uidesign.net/1999/papers/webmvc_part1.html
It gives a detailed example of a user login using MVC. It is a very good
design and might give us some ideas.
Ian Bicking wrote:
> On Thu, 2003-03-06 at 15:34, Ian Bicking wrote:
>> # __init__ is entirely specific to your component
>> def awake(self, servlet):
>> self._servlet = servlet
>> # and we also have direct accessors for requests, etc.,
>> # like Page (and a sleep, of course)
>> def respond(self):
>> # And here we do the actual work
> Now that I look at this interface, it's not nearly adequate. The more
> challenging part of an interface like this is dealing with more complex
> issues. A login component would be a much more challenging example.
> But maybe that's not too hard. It might look like:
> class Login(Component):
> def __init__(self, userManager):
> self._userManager = userManager
> def awake(self, servlet):
> Component.awake(self, servlet)
> field = self.request().field
> if field('_loginUsername_', None):
> self.login(field('_loginUsername_'), field('_loginPassword_')
> def login(self, username, password):
> if self._userManager.verifyPassword(username, password):
> user = self._userManager.userForUsername(username)
> # But what here?
> Writing the login form method is left to the reader. There's a problem
> here, that the login method can't do what it needs to do. If the login
> fails, it should present the login form again and have an error message
> (depending on the security of the application, that message might be
> "username or password incorrect" or "username does not exist", etc).
> And even if login is successful, it's nice to have some message.
> So that's two problems -- how does login provide feedback, and how does
> it take over the servlet when necessary? And there's also a bit of
> logic around using the login form, specifically, how should the servlet
> indicate that the user needs to login? Just calling the login form
> method and then returning from the servlet seems sub-optimal to me --
> well, I *really* want to use an exception for that, because that's just
> the Right Control Structure for this case. How does that exception
> translate into this Login component taking over?
> So three problems.