Skip to content

Commit

Permalink
no login via neodb itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Her Email authored and alphatownsman committed Dec 6, 2023
1 parent 051583e commit c741be8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mastodon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class TootVisibilityEnum:
UNLISTED = "unlisted"


def detect_server_info(login_domain):
def detect_server_info(login_domain) -> tuple[str, str, str]:
url = f"https://{login_domain}/api/v1/instance"
try:
response = get(url, headers={"User-Agent": USER_AGENT})
Expand Down Expand Up @@ -306,7 +306,16 @@ def get_or_create_fediverse_application(login_domain):
if not settings.MASTODON_ALLOW_ANY_SITE:
logger.error(f"Disallowed to create app for {domain}")
raise Exception("不支持其它实例登录")
if settings.SITE_DOMAIN.lower() == login_domain.lower():
raise ValueError("必须使用其它实例登录")
domain, api_domain, server_version = detect_server_info(login_domain)
if (
settings.SITE_DOMAIN.lower() == domain.lower()
or settings.SITE_DOMAIN.lower() == api_domain.lower()
):
raise ValueError("必须使用其它实例登录")
if "neodb/" in server_version:
raise ValueError("必须使用非NeoDB实例登录")
if login_domain != domain:
app = MastodonApplication.objects.filter(domain_name__iexact=domain).first()
if app:
Expand Down

0 comments on commit c741be8

Please sign in to comment.