accounts2/fas/fas controllers.py,1.3,1.4 fasLDAP.py,1.3,1.4

Michael Patrick McGrath (mmcgrath) fedora-extras-commits at redhat.com
Wed Mar 28 18:55:01 UTC 2007


Author: mmcgrath

Update of /cvs/fedora/accounts2/fas/fas
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv13716/fas

Modified Files:
	controllers.py fasLDAP.py 
Log Message:
Just making sure current changes have been committed


Index: controllers.py
===================================================================
RCS file: /cvs/fedora/accounts2/fas/fas/controllers.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- controllers.py	26 Mar 2007 18:52:07 -0000	1.3
+++ controllers.py	28 Mar 2007 18:54:59 -0000	1.4
@@ -57,41 +57,89 @@
         raise redirect("/")
 
     @expose(template="fas.templates.editAccount")
-    @identity.require(identity.in_group("sysadmin-main"))
-#    @identity.require(identity.not_anonymous())
+    @identity.require(identity.not_anonymous())
     def editAccount(self,userName=None):
         if not userName:
             userName = turbogears.identity.current.user_name
         user = Person.byUserName(userName)
         groups = Groups.byUserName(userName)
         groupsPending = Groups.byUserName(userName, unapprovedOnly=True)
-        # log.debug("Happy TurboGears Controller Responding For Duty")
         return dict(user=user, groups=groups, groupsPending=groupsPending)
 
     @expose(template="fas.templates.editGroup")
-#    @identity.require(identity.not_anonymous())
+    @identity.require(identity.not_anonymous())
     def editGroup(self, groupName):
-        groups = Groups.byGroupName(groupName)
-        return dict(groups=groups, groupName=groupName)
+        groups = Groups.byGroupName(groupName, includeUnapproved=True)
+        group = Groups.groups(groupName)[groupName]
+        userName = turbogears.identity.current.user_name
+        try:
+            myStatus = groups[userName].fedoraRoleStatus
+        except KeyError:
+            # Not in group
+            myStatus = 'Not a Member'
+        return dict(groups=groups, group=group, myStatus=myStatus)
 
     @expose(template="fas.templates.groupList")
     @exception_handler(errorMessage,rules="isinstance(tg_exceptions,ValueError)")
-#    @identity.require(identity.not_anonymous())
-    def groupList(self, search='*'):
+    @identity.require(identity.not_anonymous())
+    def listGroup(self, search='*'):
         groups = Groups.groups(search)
         userName = turbogears.identity.current.user_name
         myGroups = Groups.byUserName(userName)    
         try:
-            groups[0]
+            groups.keys()
         except:
             turbogears.flash("No Groups found matching '%s'" % search)
-            groups = []
-        return dict(printList=groups, search=search, myGroups=myGroups)
+            groups = {}
+        return dict(groups=groups, search=search, myGroups=myGroups)
+
+    @expose(template="fas.templates.resetPassword")
+    @exception_handler(errorMessage,rules="isinstance(tg_exceptions,ValueError)")
+    def resetPassword(self, userName=None, password=None, passwordCheck=None, email=None):
+        import turbomail
+
+        # Logged in
+        if turbogears.identity.current.user_name and not password:
+            return dict()
+
+        # Not logged in
+        if not (userName and password and email):
+            return dict()
+
+        if turbogears.identity.current.user_name:
+            userName = turbogears.identity.current.user_name
+        p = Person.byUserName(userName)
+
+        if password and passwordCheck and turbogears.identity.current.user_name:
+            if not password == passwordCheck:
+                turbogears.flash('Passwords do not match!')
+                return dict()
+            else:
+                turbogears.flash('Passwords do not matchasfdasdf!')
+                return dict()
+
+        if userName and email and not turbogears.identity.current.user_name:
+            if not email == p.mail:
+                turbogears.flash("'%s' Updated to %s" % (attribute, value))
+                return dict()
+            newpass = p.generatePassword(password='test')
+            message = turbomail.Message('mmcgrath at fedoraproject.org', 'mmcgrath at redhat.com', 'Fedora Project Password Reset')
+            message.plain = "You have requested a password reset - %s - %s" % (newpass['hash'], newpass['pass'])
+            turbomail.enqueue(message)
+#            p.__setattr__('userPassword', newpass['hash'])
+
+        newpass = p.generatePassword(password)
+        p.userPassword = newpass['hash']
+        return dict()
+
+    @expose(template="fas.templates.resetTrap")
+    def resetTrap(self):
+        return dict()
 
     @expose(template="fas.templates.userList")
-#    @identity.require(identity.not_anonymous())
     @exception_handler(errorMessage,rules="isinstance(tg_exceptions,ValueError)")
-    def userList(self, search='a*'):
+    @identity.require(identity.in_group("sysadmin-main"))
+    def listUser(self, search='a*'):
         users = Person.users(search)
         try:
             users[0]
@@ -102,8 +150,9 @@
 
     @expose(template='fas.templates.edit')
     @exception_handler(errorMessage,rules="isinstance(tg_exceptions,ValueError)")
-#    @identity.require(identity.not_anonymous())
-    def edit(self, userName, attribute, value, update=None):
+    @identity.require(identity.not_anonymous())
+    def editUserAttribute(self, userName, attribute, value, update=None):
+        userName = turbogears.identity.current.user_name
         attribute = attribute.encode('utf8')
         value = value.encode('utf8')
         if update:
@@ -111,3 +160,16 @@
             p.__setattr__('%s' % attribute, '%s' % value)
             turbogears.flash("'%s' Updated to %s" % (attribute, value))
         return dict(userName=userName, attribute=attribute, value=value)
+
+    @expose(template='fas.template.apply')
+    @exception_handler(errorMessage,rules="isinstance(tg_exceptions,ValueError)")
+    @identity.require(identity.not_anonymous())
+    def applyForGroup(self, groupName, action=None):
+        userName = turbogears.identity.current.user_name
+        if action:
+            Groups.apply(groupName, userName)
+        group = Groups.groups(groupName)
+
+        return dict(group=group)
+
+


Index: fasLDAP.py
===================================================================
RCS file: /cvs/fedora/accounts2/fas/fas/fasLDAP.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- fasLDAP.py	26 Mar 2007 18:52:07 -0000	1.3
+++ fasLDAP.py	28 Mar 2007 18:54:59 -0000	1.4
@@ -8,7 +8,18 @@
         self.ldapConn.simple_bind_s(who, password)
 
 class Group:
-    ''' Individual Group abstraction class '''
+    ''' Group abstraction class '''
+    def __init__(self, cn, fedoraGroupOwner, fedoraGroupType, fedoraGroupNeedsSponsor, fedoraGroupUserCanRemove, fedoraGroupJoinMsg):
+        self.cn = cn
+        self.fedoraGroupOwner = fedoraGroupOwner
+        self.fedoraGroupType = fedoraGroupType
+        self.fedoraGroupNeedsSponsor = fedoraGroupNeedsSponsor
+        self.fedoraGroupUserCanRemove = fedoraGroupUserCanRemove
+        self.fedoraGroupJoinMsg = fedoraGroupJoinMsg
+
+
+class UserGroup:
+    ''' Individual User->Group abstraction class '''
     def __init__(self, fedoraRoleApprovalDate, fedoraRoleSponsor, cn, fedoraRoleCreationDate, objectClass, fedoraRoleType, fedoraRoleStatus, fedoraRoleDomain):
         self.fedoraRoleApprovalDate = fedoraRoleApprovalDate
         self.fedoraRoleSponsor = fedoraRoleSponsor
@@ -39,7 +50,7 @@
         groupsDict = search(base, filter)
         for group in groupsDict:
             cn = group[0][1]['cn'][0]
-            groups[cn] = Group(
+            groups[cn] = UserGroup(
                 fedoraRoleApprovalDate = group[0][1]['fedoraRoleApprovalDate'][0],
                 fedoraRoleSponsor = group[0][1]['fedoraRoleSponsor'][0],
                 cn = group[0][1]['cn'][0],
@@ -53,15 +64,22 @@
         return groups
     
     @classmethod
-    def groups(self, searchExpression='*', findAttr='cn'):
-        groups = []
-        filter = '%s=%s' % (findAttr, searchExpression)
+    def groups(self, searchExpression='*', attributes=[]):
+        groups = {}
+        filter = 'cn=%s' % (searchExpression)
         base = 'ou=FedoraGroups,dc=fedoraproject,dc=org'
-        attributes = ['cn']
         groupsDict = search(base, filter, attributes)
         if groupsDict:
             for group in groupsDict:
-                groups.append(group[0][1]['cn'][0])
+                name = group[0][1]['cn'][0]
+                print group
+                groups[name] = Group(
+                    cn = group[0][1]['cn'][0],
+                    fedoraGroupOwner = group[0][1]['fedoraGroupOwner'][0],
+                    fedoraGroupType = group[0][1]['fedoraGroupType'][0],
+                    fedoraGroupNeedsSponsor = group[0][1]['fedoraGroupNeedsSponsor'][0],
+                    fedoraGroupUserCanRemove = group[0][1]['fedoraGroupUserCanRemove'][0],
+                    fedoraGroupJoinMsg = group[0][1]['fedoraGroupJoinMsg'][0])
         else:
             return None
         return groups
@@ -131,7 +149,7 @@
         for user in usersDict:
             userName = user[0][0].split(',')[2].split('=')[1]
 
-            users[userName] = Group(
+            users[userName] = UserGroup(
                 fedoraRoleApprovalDate = user[0][1]['fedoraRoleApprovalDate'][0],
                 fedoraRoleSponsor = user[0][1]['fedoraRoleSponsor'][0],
                 cn = user[0][1]['cn'][0],
@@ -206,6 +224,36 @@
         who = 'cn=%s,ou=People,dc=fedoraproject,dc=org' % who
         ldapServer.simple_bind_s(who, password)
 
+
+    def generatePassword(self,length=14,password=None,salt=''):
+        from random import Random
+        import sha
+        import sha
+        from base64 import b64encode
+        import sys
+    
+        secret = {} # contains both hash and password
+
+        if not password:
+            rand = Random() 
+            password = ''
+            # Exclude 0,O and l,1
+            righthand = '23456qwertasdfgzxcvbQWERTASDFGZXCVB'
+            lefthand = '789yuiophjknmYUIPHJKLNM'
+            for i in range(length):
+                if i%2:
+                    password = password + rand.choice(lefthand)
+                else:
+                    password = password + rand.choice(righthand)
+        
+        ctx = sha.new(password)
+        ctx.update(salt)
+        secret['hash'] = "{SSHA}%s" % b64encode(ctx.digest() + salt)
+        secret['pass'] = password
+
+        return secret
+
+
 class UserAccount:
     def __init__(self):
         self.realName = ''
@@ -268,6 +316,7 @@
     scope = ldap.SCOPE_SUBTREE
     count = 0
     timeout = 2
+    ldapServer.simple_bind_s('cn=directory manager', 'test')
     result_set = []
     try:
         result_id = ldapServer.search(base, scope, filter, attributes)




More information about the scm-commits mailing list