Latest changes

This commit is contained in:
aldrin 2021-10-21 09:05:08 +02:00
parent 517f79c9f9
commit 5206f95e3f
3 changed files with 33 additions and 161 deletions

View file

@ -3,6 +3,36 @@ from ldap3 import Server, Connection, SYNC
def create_account(username, raw_password):
connection = _get_connection()
is_success = connection.add(
f"cn={username},dc=local",
["simpleSecurityObject", "organizationalRole"],
{"userPassword": raw_password},
)
return is_success
def account_exists(username):
connection = _get_connection()
exists = connection.search(
f"cn={username},dc=local", "(objectclass=simpleSecurityObject)"
)
return exists
def is_valid_account_data(username, raw_password):
connection = _get_connection()
is_valid = connection.search(
f"cn={username},dc=local",
"(objectclass=simpleSecurityObject)",
attributes=["userPassword"],
)
if is_valid:
is_valid = connection.entries[0]["userPassword"].value == raw_password
return is_valid
def _get_connection():
server = Server("localhost")
# The SAFE_SYNC client strategy doesn't seem to be present in Buster version of ldap3. We might want to use it as
# soon as it is available (multithreading).
@ -13,9 +43,4 @@ def create_account(username, raw_password):
client_strategy=SYNC,
auto_bind=True,
)
is_success = connection.add(
f"cn={username},dc=local",
["simpleSecurityObject", "organizationalRole"],
{"userPassword": raw_password},
)
return is_success
return connection