mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +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"]
|
actions = ["get_email_login_url"]
|
||||||
|
|
||||||
def get_email_login_url(self, request, queryset):
|
def get_email_login_url(self, request, queryset):
|
||||||
|
any_valid_otps = False
|
||||||
for user in queryset:
|
for user in queryset:
|
||||||
if user.email:
|
if user.email and user.email_verification_code:
|
||||||
|
any_valid_otps = True
|
||||||
host = request.get_host()
|
host = request.get_host()
|
||||||
otp = quote(user.email_verification_code)
|
otp = quote(user.email_verification_code)
|
||||||
encoded_email = quote(user.email)
|
encoded_email = quote(user.email)
|
||||||
login_url = f"{host}/auth/magic?code={otp}&email={encoded_email}"
|
login_url = f"{host}/auth/magic?code={otp}&email={encoded_email}"
|
||||||
messages.info(request, f"Email login URL for {user.email}: {login_url}")
|
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
|
get_email_login_url.short_description = "Get email login URL" # type: ignore
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user