From 85b73458a145749f51b10a0b1d530cc43605d59c Mon Sep 17 00:00:00 2001 From: Marian Sigler Date: Fri, 21 Sep 2012 04:06:13 +0200 Subject: account: don't fail on unicode input strings. Update examples --- account.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/account.py b/account.py index 13ab60c..4792afa 100644 --- a/account.py +++ b/account.py @@ -20,12 +20,12 @@ class AccountService: ssh spline -L 5678:vm-splinux:389 -N * register a new user - >> service = AccountService(LDAP_HOST, LDAP_BASE_DN,SERVICES) + >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, ADMIN_USER, ADMIN_PW, SERVICES) >> foo = Account('foo','foo@bar.de', password='bar') - >> service.register(foo, LDAP_ADMIN_USER, LDAP_ADMIN_PASS) + >> service.register(foo) * authenticate a new user - >> service = AccountService(LDAP_HOST, LDAP_BASE_DN,SERVICES) + >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, ADMIN_USER, ADMIN_PW,, SERVICES) >> foo = service.auth('foo', 'bar') * updates an account @@ -34,16 +34,16 @@ class AccountService: >> foo.change_password('bar2', 'gitlab') # changes password for gitlab >> service.update(foo) # save changes in ldap backend # save changes in ldap backend as admin user - >> service.update(foo, LDAP_ADMIN_USER, LDAP_ADMIN_PASS) + >> service.update(foo, as_admin=True) * delete an account - >> service = AccountService(LDAP_HOST, LDAP_BASE_DN,SERVICES) + >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, LDAP_ADMIN_USER, LDAP_ADMIN_PASS, SERVICES) >> service.delete(Account) >> service.delete('foo') * find accounts - >> service = AccountService(LDAP_HOST, LDAP_BASE_DN,SERVICES) - >> all_accounts = service.find(LDAP_ADMIN_USER, LDAP_ADMIN_PASS) + >> service = AccountService(LDAP_HOST, LDAP_BASE_DN, LDAP_ADMIN_USER, LDAP_ADMIN_PASS, SERVICES) + >> all_accounts = service.find() >> print([x.uid for x in all_accounts]) """ @@ -217,12 +217,15 @@ class Account: return "" % self.uid - def change_password(self, new_password, service = None): + def change_password(self, new_password, service=None): """ Changes a password for a given service. You have to use the AccountService class to make the changes permanent. If no service is given, the root password will be changed. """ + if isinstance(new_password, unicode): + new_password = new_password.encode('utf8') + if not service: self.new_password_root = new_password else: @@ -234,4 +237,7 @@ class Account: 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 -- cgit v1.2.3-1-g7c22