[Grok-dev] login event and subscribe to

Sebastian Ware sebastian at urbantalk.se
Tue Jun 9 12:17:19 EDT 2009


Stay fresh :)

Mvh Sebastian
0707- 577 858

http://www.urbantalk.se




9 jun 2009 kl. 16.34 skrev Jens Adner:

> Well, it works !!! so easy ;-)
>
> Thank you Sebastian!!
>
> I just remove the login-submit, here is my code:
>
> class LoginForm(grok.View):
>  grok.context(Myidm)
>  """ present the login form for auth """
>
>  def update(self, login=None):
>    if (not  
> IUnauthenticatedPrincipal.providedBy(self.request.principal)):
>      # I have logged in and this is
>      utils.logme("myapp","login",self.request.principal.id,"ip  
> address")
>
>
> time for a beer ;-)
> Jens
>
>
> Sebastian Ware schrieb:
>> I use custom login views so I don't have that problem. In the 4th  
>> line I
>> set the name of the login page, which is called automatically if you
>> lack authorisation:
>>
>> def setup_pau(pau):
>>    pau['principals'] = PrincipalFolder()
>>    pau.authenticatorPlugins = ('principals',)
>>
>>    pau['session'] = session = SessionCredentialsPlugin()
>>    session.loginpagename = 'login'
>>    pau.credentialsPlugins = ('No Challenge if Authenticated',  
>> 'session',)
>>
>>
>> You'll need the page templates that render the form too:
>>
>> class Login(grok.View):
>>    grok.context(MyApp)
>>
>>    def update(self, login_submit=None, login=None):
>>        # XXX: need to display some kind of feedback when the login  
>> fails
>>        if (not
>> IUnauthenticatedPrincipal.providedBy(self.request.principal)
>>            and login_submit is not None):
>>        # I have logged in and this is
>>            # were the magic happens... such as...
>>            # self.redirect('some_destination')
>>
>>
>> class Logout(grok.View):
>>    grok.context(Interface)
>>    def render(self):
>>        session = getUtility(IAuthentication)['session']
>>        session.logout(self.request)
>>        self.redirect(self.application_url() + '/login')
>>
>> Mvh Sebastian
>>
>> 9 jun 2009 kl. 15.49 skrev Jens Adner:
>>
>>> After changing the code to "IAuthenticatedPrincipalCreated", no  
>>> results.
>>> This event is initiating every view too.
>>>
>>> I want write some infos to a mysql database as result of auth event:
>>>
>>> uid = principal.id.split('.')[-1]
>>> utils.logme("myapp","login",uid,"ip address")
>>>
>>> Currently, every browser request writes the data.
>>>
>>> Best regards
>>> Jens
>>>
>>> Sebastian Ware schrieb:
>>>> I think you could use the event [IAuthenticatedPrincipalCreated].  
>>>> Look
>>>> in [zope.app.authentication], the README.txt shares the following:
>>>>
>>>>
>>>> Authenticated Principal Creates Events
>>>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>>
>>>> We can verify that the appropriate event was published::
>>>>
>>>>>>> [event] = getEvents(interfaces.IAuthenticatedPrincipalCreated)
>>>>>>> event.principal is principal
>>>> True
>>>>>>> event.info
>>>> PrincipalInfo('bob')
>>>>>>> event.request is request
>>>> True
>>>>
>>>> The info object has the id, title, and description of the  
>>>> principal.
>>>> The info
>>>> object is also generated by the authenticator plugin, so the  
>>>> plugin may
>>>> itself have provided additional information on the info object::
>>>>
>>>>>>> event.info.title
>>>> 'Bob'
>>>>>>> event.info.id # does not include pau prefix
>>>> 'bob'
>>>>>>> event.info.description
>>>> ''
>>>>
>>>>
>>>> Mvh Sebastian
>>>>
>>>> 9 jun 2009 kl. 13.50 skrev Jens Adner:
>>>>
>>>>> Hello,
>>>>>
>>>>> I've got a question about the event "IPrincipalCreated".
>>>>>
>>>>> In my app, I use this event for putting a role to a principal:
>>>>>
>>>>> @grok.subscribe(IPrincipalCreated)
>>>>> def update_principal_info_from_ldap(event):
>>>>> principal = event.principal
>>>>> ...
>>>>> prm.assignRoleToPrincipal("adminrole", principal.id)
>>>>>
>>>>> All works fine.
>>>>>
>>>>> But this event is fireing up for every grok view. I need an  
>>>>> event for
>>>>> saving some data (login time, logout time, etc.) only for the  
>>>>> first
>>>>> successful auth of the user.
>>>>>
>>>>> I don't understand why the principal is creating for every view  
>>>>> again
>>>>> and again or why the event "knock on my door".
>>>>>
>>>>> Has anyone some hints? Is there another event I could use for  
>>>>> logging
>>>>> user infos at login and logout?
>>>>>
>>>>> Thanks
>>>>> Jens
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> ++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++ 
>>>>> ++++
>>>>> ++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++ 
>>>>> ++++
>>>>> _______________________________________________
>>>>> Grok-dev mailing list
>>>>> Grok-dev at zope.org
>>>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>>>
>>>
>>> -- 
>>> ++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++++ 
>>> ++
>>> ++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++++ 
>>> ++
>>> _______________________________________________
>>> Grok-dev mailing list
>>> Grok-dev at zope.org
>>> http://mail.zope.org/mailman/listinfo/grok-dev
>>
>
> -- 
> ++++++++ Jens Adner IuK-Zentrum Fachhochschule Schmalkalden +++++++++
> ++++++++ Fon: +49 3683688 9201  Fax: +49 3683688 989201     +++++++++
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list