summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNico von Geyso <Nico.Geyso@FU-Berlin.de>2013-03-22 22:20:00 +0100
committerNico von Geyso <Nico.Geyso@FU-Berlin.de>2013-03-22 22:20:00 +0100
commitb628a1290ab168fb9d5871a48c438e16837f0599 (patch)
tree843bd34303202cd1c80d4ae69f1b84f4550eeeaf
parentec8510603e157a528577a172196d7d8fd64b8f18 (diff)
downloadweb-b628a1290ab168fb9d5871a48c438e16837f0599.tar.gz
web-b628a1290ab168fb9d5871a48c438e16837f0599.tar.bz2
web-b628a1290ab168fb9d5871a48c438e16837f0599.zip
every attribute can now be set with _set_attribute() in Accounts
-rw-r--r--account.py15
1 files 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 "<Account uid=%s>" % 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):