Bases pour permettre aux clubs d'avoir un compte.
Bug de changement mail->compte (ou inverse) pour un adhrent. darcs-hash:20041127191341-41617-ef89b749cec49dd0b06e0a354622cdd3a7f916f4.gz
This commit is contained in:
parent
b61e87223e
commit
cb2924c574
3 changed files with 74 additions and 23 deletions
|
@ -140,6 +140,9 @@ if __name__ == '__main__' :
|
|||
s = s.split('\n')
|
||||
try :
|
||||
dn = s[0].split()[1]
|
||||
if len(s) == 2 :
|
||||
cprint("Changement du mot de passe du club %s " % ( s[1].split()[1] ),'vert')
|
||||
else :
|
||||
cprint("Changement du mot de passe de %s %s " % ( s[2].split()[1], s[1].split()[1] ),'vert')
|
||||
except :
|
||||
cprint('Erreur lors de la recherche du login','rouge')
|
||||
|
|
|
@ -19,6 +19,7 @@ bl_carte_et_definitif=0
|
|||
##Création de comptes
|
||||
# Gid des comptes créés
|
||||
gid=100
|
||||
club_gid=120
|
||||
# Shell
|
||||
login_shell='/bin/zsh'
|
||||
# Longueur maximale d'un login
|
||||
|
|
|
@ -71,12 +71,13 @@ script_utilisateur = user_tests.getuser()
|
|||
##################################################################################
|
||||
### Fonctions utiles
|
||||
def decode(s) :
|
||||
""" Retourne un unicode à paritr de s
|
||||
""" Retourne un unicode à partir de s
|
||||
s doit être en utf-8 """
|
||||
return s.decode('utf-8','ignore') # On ignore les erreurs
|
||||
|
||||
accents = "êëèéÉÈÀÙâäàûüôöÖÔîïÎÏ'çÇÿßæÆøØ" # Si modif ici modifier aussi la fonction
|
||||
def strip_accents(a) :
|
||||
""" Supression des accents de la chaîne fournie """
|
||||
a = a.replace(u'ê','e').replace(u'ë','e').replace(u'è','e').replace(u'é','e').replace(u'É','e').replace(u'È','e')
|
||||
a = a.replace(u'â','a').replace(u'ä','a').replace(u'à','a').replace(u'À','a')
|
||||
a = a.replace(u'û','u').replace(u'ü','u').replace(u'ù','u').replace(u'Ù','u')
|
||||
|
@ -109,7 +110,7 @@ def preattr(val) :
|
|||
* une liste avec un seul entier ou chaine
|
||||
|
||||
Retourne
|
||||
[ len(str(val).strip), str(val).strip ]
|
||||
[ len(str(val).strip), str(val).strip en utf-8 ]
|
||||
"""
|
||||
|
||||
t = type(val)
|
||||
|
@ -1336,21 +1337,12 @@ class adherent(base_proprietaire) :
|
|||
self._set('mail',[new])
|
||||
|
||||
# Il ne doit pas y avoir de compte
|
||||
try:
|
||||
self._data['objectClass'] = [ 'adherent' ]
|
||||
self._data.pop('uid')
|
||||
self._data.pop('cn')
|
||||
self._data.pop('shadowLastChange')
|
||||
self._data.pop('shadowMax')
|
||||
self._data.pop('shadowWarning')
|
||||
self._data.pop('loginShell')
|
||||
self._data.pop('userPassword')
|
||||
self._data.pop('uidNumber')
|
||||
self._data.pop('gidNumber')
|
||||
self._data.pop('homeDirectory')
|
||||
self._data.pop('gecos')
|
||||
self._data.pop('droits')
|
||||
except :
|
||||
|
||||
for c in [ 'uid', 'cn', 'shadowLastChange', 'shadowMax', 'shadowWarning', 'loginShell', 'userPassword', 'uidNumber', 'gidNumber', 'homeDirectory', 'gecos', 'droits','mailAlias', 'cannonicalAlias' ] :
|
||||
try: self._data.pop(c)
|
||||
except : pass
|
||||
|
||||
return new
|
||||
|
||||
def etudes(self,index_or_new) :
|
||||
|
@ -1449,9 +1441,9 @@ class adherent(base_proprietaire) :
|
|||
self._data['objectClass'] = [ 'adherent', 'posixAccount', 'shadowAccount' ]
|
||||
self._data['uid'] = [ login ]
|
||||
self._data['cn'] = [ preattr(self.Nom())[1] ]
|
||||
self._data['shadowLastChange'] = [ '12632' ]
|
||||
self._data['shadowMax'] = [ '99999']
|
||||
self._data['shadowWarning'] = [ '7' ]
|
||||
#self._data['shadowLastChange'] = [ '12632' ]
|
||||
#self._data['shadowMax'] = [ '99999']
|
||||
#self._data['shadowWarning'] = [ '7' ]
|
||||
self._data['loginShell' ] = [ shell ]
|
||||
if hash_pass :
|
||||
self._data['userPassword'] = [ hash_pass ]
|
||||
|
@ -1584,6 +1576,7 @@ class club(base_proprietaire) :
|
|||
objectClass = 'club'
|
||||
|
||||
def Nom(self,new=None) :
|
||||
""" Défini ou retourne le nom du club """
|
||||
if new==None :
|
||||
return decode(self._data.get('nom',[''])[0])
|
||||
|
||||
|
@ -1634,6 +1627,60 @@ class club(base_proprietaire) :
|
|||
annu = annuaires.locaux_clubs()
|
||||
return decode(annu.get(self.chbre(),''))
|
||||
|
||||
def compte(self,create=None) :
|
||||
""" Créé un compte au club sur zamok
|
||||
Si create = 1 créé le compte
|
||||
"""
|
||||
if create==None :
|
||||
return self._data.get('uid',[''])[0]
|
||||
|
||||
# Génération du login : club-<nom du club avec uniquement les 26 lettres de l'alphabet>
|
||||
login = 'club-'
|
||||
for l in strip_accents(self.Nom().lower()) :
|
||||
if l in string.letters : login += l
|
||||
login = preattr(login)[1]
|
||||
|
||||
if 'posixAccount' in self._data['objectClass'] :
|
||||
if login != self._data['uid'] :
|
||||
# A déja un compte
|
||||
raise ValueError(u"Le club déjà un compte. Login : %s" % self._data['uid'][0])
|
||||
else :
|
||||
return login
|
||||
|
||||
if mailexist(login) :
|
||||
raise ValueError(u"Login existant ou correspondant à un alias mail.",1)
|
||||
|
||||
home = '/home/' + login.replace('-','/')
|
||||
if os.path.exists(home) :
|
||||
raise ValueError(u'Création du compte impossible : home existant',1)
|
||||
|
||||
# Lock du mail
|
||||
self._locks.append(self.lock('mail',login))
|
||||
|
||||
if not 'compte' in self.modifs :
|
||||
self.modifs.append('compte')
|
||||
|
||||
self._data['objectClass'] = [ 'club', 'posixAccount', 'shadowAccount' ]
|
||||
self._data['uid'] = [ login ]
|
||||
self._data['cn'] = [ preattr(self.Nom())[1] ]
|
||||
self._data['loginShell' ] = [ config.login_shell ]
|
||||
|
||||
# Détermination de l'uid
|
||||
uidNumber = 1000
|
||||
while self.exist('(uidNumber=%s)' % uidNumber) :
|
||||
uidNumber += 1
|
||||
try:
|
||||
self._locks.append(self.lock('uidNumber',str(uidNumber)))
|
||||
except :
|
||||
# Quelqu'un nous a piqué l'uid que l'on venait de choisir !
|
||||
return self.compte(1)
|
||||
|
||||
self._data['uidNumber']= [ str(uidNumber) ]
|
||||
self._data['gidNumber']=[ str(config.club_gid) ]
|
||||
self._data['homeDirectory']=[ preattr(home)[1] ]
|
||||
|
||||
return decode(login)
|
||||
|
||||
class machine(base_classes_crans) :
|
||||
""" Classe de définition d'une machine """
|
||||
idn = 'mid'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue