Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 80

Añadiendo LdapUtils

Ver diferencias:

Users.py
import hashlib
from math import ceil
from operator import itemgetter
from Utils import Utils, LdapUtils
class Users(object):
......
def add(self):
maxID = str(self.getMaxID())
maxID = str(LdapUtils.getMaxID(self.ldap))
passwd = hashlib.sha1(self.password).hexdigest()
attr = [
......
('uidnumber', [maxID] ),
('gidnumber', [maxID] ),
('loginshell', ['/bin/bash'] ),
('homeDirectory', [self.whatHome() + self.user] ),
('homeDirectory', [LdapUtils.whatHome(self.type) + self.user] ),
#('jpegPhoto', ['jpegPhoto'] ),
('userpassword', [passwd])
]
......
return "OK"
def getMaxID(self): # find the maximum ID
result = self.ldap.search("ou=Group","cn=*",["gidNumber"])
numbers = []
for i in result:
numbers.append(int(i[0][1]['gidNumber'][0]))
result = self.ldap.search("ou=People","uid=*",["gidNumber","uidNumber"])
for i in result:
numbers.append(int(i[0][1]['gidNumber'][0]))
numbers.append(int(i[0][1]['uidNumber'][0]))
numbers.sort()
maxID = 1
if len(numbers) > 0:
maxID = numbers[len(numbers)-1] + 1
return maxID
def existsUsername(self):
result = self.ldap.search("ou=People","uid="+self.user,["uid"])
......
return dataUser
def whatHome(self):
if self.type == "teacher":
return "/home/profesor/"
else:
return "/home/alumnos/"
def getAllUsers(self):
result = self.ldap.search("ou=People","uid=*",["uid","cn"])
rows = []
for u in result:
rows.append([u[0][1]['uid'][0] , u[0][1]['cn'][0] ]);
return rows

Exportar a: Unified diff