how can i override byUserId() to point to byEmailAddress() in my
subclass?
I wanted to do the same thing. Here was my solution. Relevant part of
my custom User class:
# stuff below is to make Identity integration easier
@staticmethod
def byUserId(user_id):
"Returns a User object from a user_id."
return User.byEmail(user_id)
def _set_userId(self, user_id):
"Sets the user id (well, email)."
self.email = user_id
def _get_userId(self):
"Returns the email."
return self.email
# groups this user belongs to
groups= RelatedJoin( "Group")
I think I had to make a custom group too, as the mapping from user to
group wasn't automatic. In any case, here is my group class:
class Group(SQLObject):
class sqlmeta:
table="group_tbl"
groupId= UnicodeCol( length=16, alternateID=True )
displayName= UnicodeCol( length=255 )
created= DateTimeCol( default=datetime.now )
# collection of all users belonging to this group
users= RelatedJoin("User")
# collection of all permissions for this group
permissions= RelatedJoin( "TG_Permission", joinColumn="group_id",
intermediateTable="tg_group_permission",
otherColumn="permission_id" )
i had gotten similar results by adding
TG_User.byUserId = TG_User.byEmailAddress
to my User class.
the thing i'm stuck on now is that it seems to find the User according
to the sql output, yet i get a KeyError in
IdentityVisitPlugin.identity_from_form() in
turbogears.identity.visitor.py but i can't seem to find what the bad
key is.
here's some typical log output when i log in:
05/Mar/2006:19:37:24 HTTP INFO Serving HTTP on http://localhost:8080/
1/QueryOne: SELECT id, visit_key, created, expiry FROM tg_visit WHERE
visit_ke
y = '275b636ef536f9a6d129451d9b4dffa2fb4ea25b'
2006-03-05 19:37:26,312 turbogears.identity DEBUG identity_from_request
2006-03-05 19:37:26,312 turbogears.identity DEBUG Retrieving identity
for visit:
2
2006-03-05 19:37:26,312 turbogears.identity DEBUG identity_from_form,
visit_id:
2
2006-03-05 19:37:26,312 turbogears.identity DEBUG params: {'password':
'foo', 'u
ser_name': 'f...@bar.com'}
2006-03-05 19:37:26,312 turbogears.identity DEBUG user_name=f...@bar.com
pw=foo
2006-03-05 19:37:26,312 turbogears.identity DEBUG submit: None
2006-03-05 19:37:26,312 turbogears.identity DEBUG submit_x: None
2006-03-05 19:37:26,312 turbogears.identity DEBUG submit_y: None
2006-03-05 19:37:26,312 turbogears.identity DEBUG entered
validate_identity
1/Select : SELECT users.id, users.child_name, users.first_name,
users.last_na
me, users.home_zip, users.time_zone_id FROM tg_user, users WHERE
((tg_user.email
_address = 'f...@bar.com') AND (users.id = tg_user.id))
1/Select children of the class Consumer: SELECT consumers.id,
consumers.child_
name, consumers.phone FROM consumers WHERE (id IN (1))
2006-03-05 19:37:26,328 turbogears.identity DEBUG identity_from_form
KeyError: exceptions.KeyError
2006-03-05 19:37:26,328 turbogears.identity DEBUG
identity_from_http_auth
2006-03-05 19:37:26,328 turbogears.identity DEBUG identity_from_visit
2006-03-05 19:37:26,328 turbogears.identity DEBUG
identity_from_request: found identity in
<bound method IdentityVisitPlugin.identity_from_visit of
<turbogears.identity.v
isitor.IdentityVisitPlugin object at 0x0130D810>>
2006-03-05 19:37:26,328 turbogears.identity INFO Identity is
available...
2006-03-05 19:37:26,328 turbogears.identity DEBUG record_request,
identity: <tur
bogears.identity.soprovider.SqlObjectIdentity object at 0x01388B10>
2006-03-05 19:37:26,328 turbogears.identity DEBUG record_request,
provider: <tur
bogears.identity.soprovider.SqlObjectIdentityProvider object at
0x013164F0>
1/QueryOne: SELECT id, visit_id, user_id FROM tg_visit_identity WHERE
visit_id
= 2
1/COMMIT :
1/ROLLBACK:
1/QueryOne: SELECT id, visit_key, created, expiry FROM tg_visit WHERE
visit_ke
y = '275b636ef536f9a6d129451d9b4dffa2fb4ea25b'
2006-03-05 19:37:26,342 turbogears.identity DEBUG identity_from_request
2006-03-05 19:37:26,342 turbogears.identity DEBUG Retrieving identity
for visit:
2
2006-03-05 19:37:26,342 turbogears.identity DEBUG identity_from_form,
visit_id:
2
2006-03-05 19:37:26,342 turbogears.identity DEBUG params: {}
2006-03-05 19:37:26,342 turbogears.identity DEBUG identity_from_form
KeyError: exceptions.KeyError
2006-03-05 19:37:26,342 turbogears.identity DEBUG
identity_from_http_auth
2006-03-05 19:37:26,342 turbogears.identity DEBUG identity_from_visit
2006-03-05 19:37:26,342 turbogears.identity DEBUG identity_from_request
found in
<bound method IdentityVisitPlugin.identity_from_visit of
<turbogears.identity.visitor.IdentityVisitPlugin object at 0x0130D810>>
2006-03-05 19:37:26,342 turbogears.identity INFO Identity is
available...
2006-03-05 19:37:26,358 turbogears.identity DEBUG record_request,
identity: <tur
bogears.identity.soprovider.SqlObjectIdentity object at 0x01388C10>
2006-03-05 19:37:26,375 turbogears.identity DEBUG record_request,
provider: <tur
bogears.identity.soprovider.SqlObjectIdentityProvider object at
0x013164F0>
2006-03-05 19:37:26,625 turbokid.kidsupport DEBUG Recompiling template
for turbo
gears.fastdata.templates.sitetemplate
2006-03-05 19:37:26,640 turbokid.kidsupport DEBUG Recompiling template
for myproject
nium.templates.login
2006-03-05 19:37:26,828 turbokid.kidsupport DEBUG Applying template
myproject.te
mplates.login
1/ROLLBACK:
127.0.0.1 - - [05/Mar/2006:19:37:27] "POST /secured HTTP/1.1" 403 3017
also it seems to go through the authentication process twice? i see
identity_from_form() being called twice, the second time without any
parameters. regardless, i always end up back on the login page.
any help is appreciated!
thanks for your help!