From b628a1290ab168fb9d5871a48c438e16837f0599 Mon Sep 17 00:00:00 2001 From: Nico von Geyso Date: Fri, 22 Mar 2013 22:20:00 +0100 Subject: every attribute can now be set with _set_attribute() in Accounts --- account.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/account.py b/account.py index 3f563c9..e9823df 100644 --- a/account.py +++ b/account.py @@ -179,7 +179,7 @@ class AccountService: else: self._bind_as_user(account.uid, account.password) - attr = [(ldap.MOD_REPLACE, 'mail', account.mail)] + attr = [(ldap.MOD_REPLACE, k, v) for k, v in account.attributes.items()] dn = self._format_dn([('uid',account.uid),('ou','users')]) self.connection.modify_s(dn, attr) self._alter_passwords(account, as_admin=as_admin) @@ -318,13 +318,14 @@ class Account: """ def __init__(self, uid, mail, services=[], dn=None, password=None): self.uid = uid.encode('utf8') if isinstance(uid, unicode) else uid - self.mail = mail.encode('utf8') if isinstance(mail, unicode) else mail self.services = services self.dn = dn self.password = password.encode('utf8') if isinstance(password, unicode) else password self.new_password_root = None self.new_password_services = {} + self.attributes = {} + self._set_attribute('mail', mail) def __repr__(self): return "" % self.uid @@ -350,16 +351,18 @@ class Account: else: self.new_password_services[service] = (old_password, new_password) + def _set_attribute(self, key, value): + if isinstance(value, unicode): + value = value.encode('utf8') + + self.attributes[key] = value def change_email(self, new_mail): """ Changes the mail address of an account. You have to use the AccountService class to make changes permanent. """ - if isinstance(new_mail, unicode): - new_mail = new_mail.encode('utf8') - - self.mail = new_mail + self._set_attribute('mail', new_mail) class NoSuchUserError(ValueError): -- cgit v1.2.3-1-g7c22