diff --git a/objets.py b/objets.py index 0e95dd8..6d4d673 100644 --- a/objets.py +++ b/objets.py @@ -948,7 +948,6 @@ class proprio(CransLdapObject): return self['uid'][0] elif login: - fn = crans_utils.strip_accents(unicode(self['prenom'][0]).capitalize()) ln = crans_utils.strip_accents(unicode(self['nom'][0]).capitalize()) login = crans_utils.strip_spaces(crans_utils.strip_accents(login), by=u'-').lower() if not re.match('^[a-z][-a-z]{1,15}$', login): @@ -956,24 +955,40 @@ class proprio(CransLdapObject): if crans_utils.mailexist(login): raise ValueError("Login existant ou correspondant à un alias mail.") - home = u'/home/' + login - if os.path.exists(home): - raise ValueError('Création du compte impossible : home existant') + if self.ldap_name == u'adherent': - if os.path.exists("/var/mail/" + login): - raise ValueError('Création du compte impossible : /var/mail/%s existant' % str(login)) + home = u'/home/' + login[0] + '/' + login + if os.path.exists(home): + raise ValueError('Création du compte impossible : home existant') - self._modifs['objectClass'] = [u'adherent', u'cransAccount', u'posixAccount', u'shadowAccount'] - self['uid'] = [login] - self['homeDirectory'] = [home] - self['mail'] = [login + u"@crans.org"] - calias = crans_utils.strip_spaces(fn) + u'.' + crans_utils.strip_spaces(ln) + '@crans.org' - if crans_utils.mailexist(calias): - calias = login + u'@crans.org' + if os.path.exists("/home/mail/" + login): + raise ValueError('Création du compte impossible : /home/mail/%s existant' % str(login)) + + fn = crans_utils.strip_accents(unicode(self['prenom'][0]).capitalize()) + self._modifs['objectClass'] = [u'adherent', u'cransAccount', u'posixAccount', u'shadowAccount'] + self['homeDirectory'] = [home] + self['cn'] = [fn + u' ' + ln] + self['mail'] = [login + u"@crans.org"] + calias = crans_utils.strip_spaces(fn) + u'.' + crans_utils.strip_spaces(ln) + '@crans.org' if crans_utils.mailexist(calias): - raise ValueError('Creation impossible, Alias canonique déjà pris, merci de choisir un autre login') - self['canonicalAlias'] = [calias] - self['cn'] = [fn + u' ' + ln] + calias = login + u'@crans.org' + if crans_utils.mailexist(calias): + raise ValueError('Creation impossible, Alias canonique déjà pris, merci de choisir un autre login') + self['canonicalAlias'] = [calias] + + else: + # C'est un club + home = u'/home/c/' + login + if os.path.exists(home): + raise ValueError('Création du compte impossible : home existant') + if os.path.exists("/home/mail/" + login): + raise ValueError('Création du compte impossible : /home/mail/%s existant' % str(login)) + self._modifs['objectClass'] = [u'club', u'cransAccount', u'posixAccount', u'shadowAccount'] + self['homeDirectory'] = [home] + self['cn'] = [ln] + + # Les attributs communs + self['uid'] = [login] self['loginShell'] = [unicode(shell)] if hash_pass: self['userPassword'] = [unicode(hash_pass)]