mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Handle scenario where no valid otps for selected users on admin panel
This commit is contained in:
@@ -152,13 +152,17 @@ class KhojUserAdmin(UserAdmin, unfold_admin.ModelAdmin):
|
||||
actions = ["get_email_login_url"]
|
||||
|
||||
def get_email_login_url(self, request, queryset):
|
||||
any_valid_otps = False
|
||||
for user in queryset:
|
||||
if user.email:
|
||||
if user.email and user.email_verification_code:
|
||||
any_valid_otps = True
|
||||
host = request.get_host()
|
||||
otp = quote(user.email_verification_code)
|
||||
encoded_email = quote(user.email)
|
||||
login_url = f"{host}/auth/magic?code={otp}&email={encoded_email}"
|
||||
messages.info(request, f"Email login URL for {user.email}: {login_url}")
|
||||
if not any_valid_otps:
|
||||
messages.error(request, "No valid OTPs found for the selected users.")
|
||||
|
||||
get_email_login_url.short_description = "Get email login URL" # type: ignore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user