summaryrefslogtreecommitdiffstats
path: root/accounts/backend
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-09-30 20:26:13 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2016-09-30 20:26:13 +0200
commitd29d7eebc3bbbbe2bb019ddb32355d62658e5b8d (patch)
treefa8ceb7e9579bd7d9988654d727c1d8bf35b30d2 /accounts/backend
parent13569141a629927ddd4198f124139a124bbffaee (diff)
downloadweb-d29d7eebc3bbbbe2bb019ddb32355d62658e5b8d.tar.gz
web-d29d7eebc3bbbbe2bb019ddb32355d62658e5b8d.tar.bz2
web-d29d7eebc3bbbbe2bb019ddb32355d62658e5b8d.zip
backend/user: Split _store and register
Separate the method to persist a new account from the register method so that common checks could be done in the base class and the concrete implementations can overwrite only the storage part.
Diffstat (limited to 'accounts/backend')
-rw-r--r--accounts/backend/user/__init__.py16
-rw-r--r--accounts/backend/user/dummy.py8
-rw-r--r--accounts/backend/user/ldap.py5
3 files changed, 16 insertions, 13 deletions
diff --git a/accounts/backend/user/__init__.py b/accounts/backend/user/__init__.py
index af0cc63..57ba952 100644
--- a/accounts/backend/user/__init__.py
+++ b/accounts/backend/user/__init__.py
@@ -107,9 +107,15 @@ class Backend(object):
def register(self, account):
"""
- Persists an account in the backend.
+ Register a new user account.
+
+ This message checks the given account for plausibility,
+ get a new uidNumber and store the account into the backend.
"""
- raise NotImplementedError()
+ if account.password is None:
+ raise ValueError("Password required for register")
+
+ self._store(account)
def update(self, account, as_admin=False):
"""
@@ -122,3 +128,9 @@ class Backend(object):
Deletes an account permanently.
"""
raise NotImplementedError()
+
+ def _store(self, account):
+ """
+ Persists an account in the backend.
+ """
+ raise NotImplementedError()
diff --git a/accounts/backend/user/dummy.py b/accounts/backend/user/dummy.py
index cc43dc5..867db2e 100644
--- a/accounts/backend/user/dummy.py
+++ b/accounts/backend/user/dummy.py
@@ -64,13 +64,7 @@ class DummyBackend(Backend):
return results
- def register(self, account):
- """
- Persists an account in the backend.
- """
- if account.password is None:
- raise ValueError("Password required for register")
-
+ def _store(self, account):
self._storage.append(deepcopy(account))
def update(self, account, as_admin=False):
diff --git a/accounts/backend/user/ldap.py b/accounts/backend/user/ldap.py
index 6ab02c6..ea1b7fc 100644
--- a/accounts/backend/user/ldap.py
+++ b/accounts/backend/user/ldap.py
@@ -92,10 +92,7 @@ class LdapBackend(Backend):
return accounts
- def register(self, account):
- """
- Persists an account in the backend.
- """
+ def _store(self, account):
conn = self._connect_as_admin()
user_dn = self._format_dn([('uid', account.uid), ('ou', 'users')])