[EMAIL PROTECTED] schrieb:
> Florent Aide a écrit :
>> I would deactivate visit and add my own filter as you show here in
>> order to not modify TG's code that's why I said creating a id provider
>> does not need TG's code to be changed.
>
> Yes I could write a new visit plugin. But I don't want to do that, I'm
> not sure to do a good job.
It's actually not so difficult since you don't need to write from
scratch. Just inherit and copy from the existing plugin:
------------------------------------------------
from identity.visitor import IdentityVisitPlugin
class CompanyIdentityVisitPlugin(IdentityVisitPlugin):
def __init__(self):
IdentityVisitPlugin.__init__(self)
self.company_field = get("identity.form.company", "company")
def identity_from_form(self, visit_key):
params = cherrypy.request.params
if params.has_key(self.submit_button_name):
try:
company = params.pop(self.company_field)
user_name = params.pop(self.user_name_field)
pw = params.pop(self.password_field)
if '@' in company or '@' not in user_name:
identity = None
else:
user_name = '[EMAIL PROTECTED]' % (user_name, company)
submit = params.pop(self.submit_button_name, None)
submit_x = params.pop("%s.x"
% self.submit_button_name, None)
submit_y = params.pop("%s.y"
% self.submit_button_name, None)
set_login_attempted(True)
identity = self.provider.validate_identity(
user_name, pw, visit_key)
if identity is None:
log.warning(
"The credentials specified weren't valid")
return identity
except KeyError:
log.error("Missing fields in login form")
visit.enable_visit_plugin(CompanyIdentityVisitPlugin())
------------------------------------------------
If you don't like to have the company in your user_name column and want
to add a company column to your tg_user class instead, you need to
replace the provider was well (as explained by Florent). Again you can
simply inherit and copy from the existing provider, and only overwrite
validate_identity method. The method should now take an additional
company parameter, and the only line you need to change in the method is
user = user_class.query.filter_by(user_name=user_name).first().
In the identity_from_form() method above you would then just call
validate_identity witht he additional company parameter instead of
building a new user_name with the '@' sign.
-- Christoph
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---