Skip to content

Commit

Permalink
Use first and last name for cn and sn in ldap user
Browse files Browse the repository at this point in the history
  • Loading branch information
txels committed Apr 8, 2024
1 parent bffd82f commit b9ffa5a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions humans/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ def connect() -> LDAPObject:
return connection


def create_user(connection, username, email):
name = username.encode("utf-8")
user_dn = f"uid={username},{ORG_UNIT}"
def create_user(connection, user, email):
name = user.username.encode("utf-8")
user_dn = f"uid={user.username},{ORG_UNIT}"

user_attrs = {}
user_attrs["objectClass"] = [b"pilotPerson"]
user_attrs["cn"] = (name,)
user_attrs["cn"] = (user.first_name.encode("utf-8"),)
user_attrs["sn"] = (user.last_name.encode("utf-8"),)
user_attrs["mail"] = (email.encode("utf-8"),)
user_attrs["sn"] = (name,)
user_attrs["uid"] = (name.lower(),)
Expand Down
3 changes: 1 addition & 2 deletions humans/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def save(self, *args, **kwargs):

def __ldap__save(self):
connection = directory.connect()
directory.create_user(connection, self.username, self.email)
self.is_active = False
directory.create_user(connection, self, self.email)
return

def __ldap__set_password(self, password):
Expand Down
2 changes: 2 additions & 0 deletions shipanaro/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class ShipanaroModelAdmin(ModelAdmin):

class ShipanaroUserAdmin(UserAdmin, ShipanaroModelAdmin):
list_display = (
"id",
"username",
"email",
"first_name",
"last_name",
"is_staff",
"is_active",
"date_joined",
)


Expand Down

0 comments on commit b9ffa5a

Please sign in to comment.