diff --git a/arthur/exts/directory/ldap.py b/arthur/exts/directory/ldap.py index 79d5924..78a7e41 100644 --- a/arthur/exts/directory/ldap.py +++ b/arthur/exts/directory/ldap.py @@ -123,16 +123,18 @@ async def generate_creds(self, interaction: discord.Interaction, _button: ui.But ) return - bootstrap_type, password = await self.cog.bootstrap(user) + bootstrap_type, password, uid = await self.cog.bootstrap(user) if bootstrap_type == BootstrapType.CREATION: title = "Account Creation" logger.info(f"Created account for {user}") else: title = "Password Reset" - logger.info(f"Reset password for {user}") + logger.info(f"Reset password for {user} with {uid}") - content = CREDENTIALS_SECTION.format(title=title, username=user.name, password=password) + content = CREDENTIALS_SECTION.format( + title=title, username=uid or user.name, password=password + ) await interaction.response.send_message(content, ephemeral=True) @@ -221,14 +223,14 @@ async def on_member_update(self, before: discord.Member, after: discord.Member) if LDAP_BASE_STAFF_ROLE in before_roles or LDAP_BASE_STAFF_ROLE in after_roles: self.sync_users() - async def bootstrap(self, user: discord.Member) -> tuple[BootstrapType, str]: + async def bootstrap(self, user: discord.Member) -> tuple[BootstrapType, str, str | None]: """Bootstrap a user into the LDAP directory, either creating or resetting the password.""" if ldap_user := await ldap.find_by_discord_id(user.id): password = secrets.token_urlsafe(20) keycloak.force_password_reset(ldap_user.uid, password) - return BootstrapType.RESET, password + return BootstrapType.RESET, password, ldap_user.uid generated_pw = freeipa.create_user( user.name, @@ -239,7 +241,7 @@ async def bootstrap(self, user: discord.Member) -> tuple[BootstrapType, str]: await self.cleanup_bootstrap(user) - return BootstrapType.CREATION, generated_pw + return BootstrapType.CREATION, generated_pw, None async def cog_load(self) -> None: # noqa: C901, PLR0912 """Verify the bootstrap channel is setup as intended."""