Commits

Gael Pasgrimaud committed 781337b Merge

merge

  • Participants
  • Parent commits 1a7053b, 87ff461

Comments (0)

Files changed (3)

File shabti/templates/moinmoin/+package+/model/user.py_tmpl

-from datetime import datetime
-from elixir import *
-from elixir import events
-import hashlib
-from {{package}}.model import Session, metadata
-
-options_defaults['inheritance'] = 'multi'
-
-def encrypt_value(value):
-    return hashlib.sha1(value).hexdigest()
-
-class NotAuthenticated(Exception):pass
-
-class User(Entity):
-    username = Field(Unicode(30), unique=True) # undocumented
-    firstname = Field(Unicode(), unique=True) # undocumented
-    lastname = Field(Unicode(), unique=True) # undocumented
-    password = Field(String(40)) # undocumented
-    password_check = Field(String(40)) # undocumented
-    email = Field(String(255)) # undocumented
-    created = Field(DateTime) # undocumented
-    active = Field(Boolean) # undocumented
-    groups = ManyToMany('Group')
-    using_options(shortnames=True)
-    
-    def __repr__(self):
-        return '<%r %r, email: %r, created: %s, active: %s>' \
-               % (self.__class__.__name__.capitalize(), self.username, 
-                  self.email, self.created.ctime(), self.active)
-    
-    @classmethod
-    def authenticate(cls, username, password):
-        try:
-            user=cls.query.filter_by(username=username, active=True).one()
-            if user and encrypt_value(password) == user.password:
-                return user
-        except Exception:
-            raise NotAuthenticated
-        raise NotAuthenticated
-    
-    def validate_password(user, password):
-        return encrypt_value(password) == user.password
-    
-    @events.before_insert
-    @events.before_update
-    def encrypt_password(self):
-        if self.password and self.password != self.password_check:
-            self.password = encrypt_value(self.password)
-            self.password_check = self.password
-    
-    @property
-    def permissions(self):
-        permissions = set()
-        for g in self.groups:
-            permissions = permissions | set(g.permissions)
-        return permissions        
-    
-    @property
-    def permission_names(self):
-        return [p.name for p in self.permissions]
-    
-    def has_permission(self, perm):
-        return (perm in self.permission_names)
-    
-
-
-class Group(Entity):
-    name = Field(Unicode(30)) # undocumented
-    description = Field(Unicode(255)) # undocumented
-    created = Field(DateTime) # undocumented
-    active = Field(Boolean) # undocumented
-    users = ManyToMany('User')
-    permissions = ManyToMany('Permission')
-    using_options(shortnames=True)
-    
-    def __repr__(self):
-        return '<%r %r, description: %r, created: %s, active: %s>' \
-               % (self.__class__.__name__.capitalize(), self.name, 
-                  self.description, self.created.ctime(), self.active)
-    
-
-
-class Permission(Entity):
-    name = Field(Unicode(30)) # undocumented
-    description = Field(Unicode(255)) # undocumented
-    groups = ManyToMany('Group', onupdate = 'CASCADE', 
-                        ondelete = 'CASCADE', uselist = True)
-    using_options(shortnames=True)
-    
-    def __repr__(self):
-        return '<%r %r, description: %r>' \
-               % (self.__class__.__name__.capitalize(), 
-                  self.name, self.description)
-    
-
-
-__all__=['User', 'Permission', 'Group', 'NotAuthenticated']

File shabti/templates/moinmoin/+package+/websetup.py_tmpl

 from pylons import config
 from elixir import *
 from {{package}} import model
-from {{package}}.model import user
+from {{package}}.model import identity
 
 def setup_app(command, conf, vars):
     """Place any commands to setup {{package}} here"""
     import datetime
     import hashlib
     model.metadata.create_all()
-    gadmin = model.user.Group(
+    gadmin = identity.Group(
             name = "Administrators",
             description = u"Administration group",
             created = datetime.datetime.utcnow(),
     # model.Session.commit()
     # Check the status
     g = model.Session.query(
-            model.user.Group).filter_by(
+            identity.Group).filter_by(
                 name="Administrators").all()
     assert len(g) == 1
     assert g[0] == gadmin
-    admin = model.user.User(
+    admin = identity.User(
                 username = u"admin", 
                 firstname = u"System",
                 lastname = u"Administrator",
     model.Session.commit()
     # Check the status
     u = model.Session.query(
-            model.user.User).filter_by(
+            identity.User).filter_by(
                 username=u"admin").all()
     assert len(u) == 1
     assert u[0] == admin

File shabti/templates/moinmoin/data/moin/config/wikiconfig.py_tmpl

         auth_user_id = req.env.get('beaker.session', {}).get('AUTH_USER_ID', 0)
         if auth_user_id:
             user_obj = model.Session.query(model.User).get(auth_user_id)
-            auth_username = user_obj.firstname + user_obj.lastname
+            auth_username = user_obj.username
             from MoinMoin.user import User as MoinUser
             # giving auth_username to User constructor 
             # means that authentication has already been done.