Refactor code

This commit is contained in:
PCoder 2019-02-04 20:12:56 +01:00
parent 67c1dcb1f3
commit a0ecec665e
2 changed files with 20 additions and 21 deletions

View file

@ -177,6 +177,23 @@ MEDIA_URL = FORCE_SCRIPT_NAME + 'media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LDAP_SEARCH_BASE=config(
'LDAP_SEARCH_BASE',
default='ou=customer,dc=ungleich,dc=ch'
)
LDAP_MAX_UID_PATH = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'ldap_max_uid_file'
)
LDAP_IPV6_WORK_USER_GROUP = config('LDAP_IPV6_WORK_USER_GROUP', cast=int)
LDAP_DEFAULT_START_UID = config(
'LDAP_DEFAULT_START_UID', cast=int, default=10000
)
LDAP_CUSTOMER_DN = config('LDAP_CUSTOMER_DN', default='ou=customer,dc=ungleich,dc=ch')
AUTH_LDAP_SERVER_URI = config('AUTH_LDAP_SERVER_URI')
AUTH_LDAP_BIND_DN = config('AUTH_LDAP_BIND_DN')
@ -184,7 +201,7 @@ AUTH_LDAP_BIND_PASSWORD = config('AUTH_LDAP_BIND_PASSWORD')
AUTH_LDAP_USER_SEARCH = LDAPSearchUnion(
LDAPSearch("ou=users,dc=ungleich,dc=ch",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
LDAPSearch("ou=customers,dc=ungleich,dc=ch",
LDAPSearch(LDAP_CUSTOMER_DN,
ldap.SCOPE_SUBTREE, "(uid=%(user)s)"),
)
@ -210,24 +227,6 @@ LOGGING = {
},
}
LDAP_SEARCH_BASE=config(
'LDAP_SEARCH_BASE',
default='ou=customer,dc=ungleich,dc=ch'
)
LDAP_MAX_UID_PATH = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'ldap_max_uid_file'
)
LDAP_IPV6_WORK_USER_GROUP = config('LDAP_IPV6_WORK_USER_GROUP', cast=int)
LDAP_DEFAULT_START_UID = config(
'LDAP_DEFAULT_START_UID', cast=int, default=10000
)
LDAP_USER_DN = config('LDAP_USER_DN', default='ou=customer,dc=ungleich,dc=ch')
if config('ENABLE_DEBUG_LOG', cast=bool, default=False):
loggers_dict = {}
MODULES_TO_LOG = config('MODULES_TO_LOG', 'django')

View file

@ -20,7 +20,7 @@ def create_user(user, password, firstname, lastname, email):
results = True
while results:
results = conn.search(
search_base=settings.LDAP_SEARCH_BASE,
search_base=settings.LDAP_CUSTOMER_DN,
search_filter=(
'(&(objectClass=inetOrgPerson)(objectClass=posixAccount)'
'(objectClass=top)(uidNumber={uidNumber}))'.format(
@ -37,7 +37,7 @@ def create_user(user, password, firstname, lastname, email):
logger.debug("{uid} does not exist. Using it".format(uid=uidNumber))
set_max_uid(uidNumber)
w = Writer(conn, obj_new_user)
dn = 'uid=%s,%s' % (user, settings.LDAP_USER_DN)
dn = 'uid=%s,%s' % (user, settings.LDAP_CUSTOMER_DN)
w.new(dn)
w[0].givenName = firstname
w[0].sn = lastname