Skip to content

Commit

Permalink
Use LDAP uid in reset message
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekashok1221 committed Jul 30, 2024
1 parent 396632c commit 3944309
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions arthur/exts/directory/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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."""
Expand Down

0 comments on commit 3944309

Please sign in to comment.