[Seaside] [ENH] Session with (lazy) form-based login [with
attachment]
miso.list at auf.net
miso.list at auf.net
Wed Mar 24 18:08:33 CET 2004
Hi - here are two tiny classes (basically 2 methods) implementing:
* logging in a user at the session level (allowing the login to be
shared by multiple component)
* the login is form-based (unlike WAAuthenticatedSession)
* the login taps into your existing database of users (ie does not
restrict you to a single user as WAAuthenticatedSession does). You
need to plug in your own code to tap your db, of course. See
#handleLogin
* the login is lazy in that it occurs only when a component asks for
'self session user'. This is easy to change into a session-initial
login, see the comment in SeasideLoginSession.
Since it took me a couple of hours to find how to do this in Seaside,
I thought I'd spare someone else :) Also, since I'm fairly new to
Seaside, comments or criticisms are welcome.
Michal
-------------- next part --------------
WAComponent subclass: #SeasideLogin
instanceVariableNames: 'username password '
classVariableNames: ''
poolDictionaries: ''
category: 'Seaside-Enh'!
!SeasideLogin commentStamp: 'miso 3/24/2004 11:01' prior: 0!
I am a form-based login page, checking your login info against a database of users and reporting succesful logins back to my session. I am designed to be called from SeasideLoginSession. You need to customise my #handleLogin in order to match your database of users.!
!SeasideLogin methodsFor: 'as yet unclassified' stamp: 'miso 3/24/2004 10:52'!
handleLogin
username isEmptyOrNil ifTrue: [^ self].
password isEmptyOrNil ifTrue: [^ self].
" plug your user-checking code here. Here is mine:
candidate _ People everybody detect: [:person | person username = username] ifNone: [].
candidate ifNil: [^ self].
candidate password = password ifTrue: [self session user: password].
"! !
!SeasideLogin methodsFor: 'as yet unclassified' stamp: 'miso 3/24/2004 10:55'!
renderContentOn: html
html attributeAt: 'align' put: 'center'.
html form: [
html attributes align: 'center'; bgcolor: Color random hex; cellspacing: '10'.
html table: [
html tableRowWith: 'nickname' with: [html textInputWithCallback: [:v | username _ v]].
html tableRowWith: 'Password: ' with: [html passwordInputWithCallback: [:v | password _ v]]].
html break; submitButtonWithAction: [self handleLogin]].! !
WAControllerSession subclass: #SeasideLoginSession
instanceVariableNames: 'user '
classVariableNames: ''
poolDictionaries: ''
category: 'Seaside-Enh'!
!SeasideLoginSession commentStamp: 'miso 3/24/2004 10:59' prior: 0!
This session will ask you to login as soon as anybody asks for its user - but leaves you in peace until then. To adapt it to your database of users, you need to customise the code in SeasideLogin #handleLogin.
[If you want to enforce logging in before the user does anything, just move the #ifNil: block in #user into #start, and then call 'super start'.]!
!SeasideLoginSession methodsFor: 'accessing' stamp: 'miso 3/21/2004 03:02'!
user
user ifNil: [
| realRoot |
realRoot _ root.
root _ SeasideLogin new.
[user isNil] whileTrue: [self render].
root _ realRoot].
^ user! !
!SeasideLoginSession methodsFor: 'accessing' stamp: 'miso 3/21/2004 01:04'!
user: anObject
user _ anObject! !
More information about the Seaside
mailing list