Benutzer-Werkzeuge

Webseiten-Werkzeuge


python:grok-1.4-ldapauth

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
python:grok-1.4-ldapauth [2011/10/19 11:14] – angelegt jenadpython:grok-1.4-ldapauth [2017/11/15 09:08] (aktuell) – gelöscht jenad
Zeile 1: Zeile 1:
  
-app.py 
-<code python> 
-import grok 
-import rolesAndPerms 
-import ldapauth 
- 
-from demo import resource 
- 
-from zope.pluggableauth.authentication import PluggableAuthentication 
-from zope.authentication.interfaces import IAuthentication 
- 
- 
-class Demo(grok.Application, grok.Container): 
-    grok.local_utility( 
-         PluggableAuthentication, provides=IAuthentication, 
-              setup=ldapauth.setup_authentication, 
-                   ) 
- 
-class Index(grok.View): 
-    grok.require("mysite.View") 
-    def update(self): 
-        resource.style.need() 
- 
- 
-from zope.interface import Interface 
-from zope import schema 
- 
-class ILoginForm(Interface): 
-    login = schema.BytesLine(title=u'Username', required=True) 
-    password = schema.Password(title=u'Password', required=True) 
- 
-class MyLogin(grok.Form): 
-    grok.context(Interface) 
-    grok.require('zope.Public') 
- 
-    form_fields = grok.Fields(ILoginForm) 
- 
-    @grok.action('login') 
-    def handle_login(self, **data): 
-      uid=self.request.get('camefrom','hans') 
-      self.redirect(self.request.form.get('camefrom', uid)) 
-         
-from zope.pluggableauth.interfaces import ILogout 
-from zope.authentication.interfaces import IUnauthenticatedPrincipal 
- 
-from zope.component import getUtility 
-class Logout(grok.View): 
-    grok.context(Interface) 
-    grok.require('zope.Public') 
- 
-    def update(self): 
-        if not IUnauthenticatedPrincipal.providedBy(self.request.principal): 
-            auth = getUtility(IAuthentication) 
-            ILogout(auth).logout(self.request) 
-    def render(self): 
-      return "logout successful!!" 
- 
-</code> 
- 
-rolesAndPerms.py 
-<code python> 
-import grok 
-from zope.pluggableauth.interfaces import IAuthenticatedPrincipalCreated 
-from zope.securitypolicy.interfaces import IRolePermissionManager,IPrincipalRoleManager 
- 
-@grok.subscribe(IAuthenticatedPrincipalCreated) 
-def update_principal_info_from_ldap(event): 
- principal = event.principal 
- app = grok.getSite() 
- prm = IPrincipalRoleManager(app) 
- prm.assignRoleToPrincipal('mysite.Viewer', principal.id) 
- 
- 
-class ViewDemo(grok.Permission): 
-    grok.name('mysite.View') 
-    grok.title('View this Demo') # optional 
- 
-class Viewer(grok.Role): 
-    """ 
-    A Viewer can view. 
-    """ 
-    grok.name('mysite.Viewer') 
-    grok.title('The Viewer') 
-    grok.description('A Viewer.') 
-    grok.permissions('mysite.View') 
-    # alternatively, use permission names 
-    # grok.permissions( 
-    #    'paint.ViewPainting', 'paint.EditPainting', 'paint.ErasePainting') 
- 
-</code> 
python/grok-1.4-ldapauth.1319015648.txt.gz · Zuletzt geändert: 2024/08/07 13:35 (Externe Bearbeitung)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki