From 31ee293b7aac69e2b900f52d9151b0c98d2805bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=84=EB=A5=B4=ED=8E=98?= Date: Sat, 10 Feb 2024 00:13:06 +0900 Subject: [PATCH] fix: separate whitelist and no new user --- config.example.json | 3 ++- src/backend/router.ts | 7 ++++++- src/common/types/error-code.ts | 1 + src/frontend/langs/en-US.json | 3 ++- src/frontend/langs/ko-KR.json | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/config.example.json b/config.example.json index e268528..f0cbbbc 100644 --- a/config.example.json +++ b/config.example.json @@ -13,7 +13,8 @@ "admin": { "username": "your_user_name", "host": "your-instance-host" - } + }, + "noNewUserAllowed": false, "whitelist": { "enabled": false, "instances": [ diff --git a/src/backend/router.ts b/src/backend/router.ts index 122ca35..06b647b 100644 --- a/src/backend/router.ts +++ b/src/backend/router.ts @@ -180,11 +180,16 @@ router.get('(.*)', async (ctx) => { async function login(ctx: Context, user: Record, host: string, token: string) { const isNewcomer = !(await getUser(user.username as string, host)); - if (isNewcomer && config.whitelist.enabled && !config.whitelist.instances.includes(host)) { + if (isNewcomer && config.noNewUserAllowed) { await die(ctx, 'noNewUserAllowed', 403); return; } + if (config.whitelist.enabled && !config.whitelist.instances.includes(host)) { + await die(ctx, 'notWhitelisted', 403); + return; + } + await upsertUser(user.username as string, host, token); const u = await getUser(user.username as string, host); diff --git a/src/common/types/error-code.ts b/src/common/types/error-code.ts index 9faa479..f6df8e3 100644 --- a/src/common/types/error-code.ts +++ b/src/common/types/error-code.ts @@ -8,6 +8,7 @@ export const errorCodes = [ 'hostNotFound', 'invalidHostFormat', 'noNewUserAllowed', + 'notWhitelisted', 'other', ] as const; diff --git a/src/frontend/langs/en-US.json b/src/frontend/langs/en-US.json index 5fe3310..608f949 100644 --- a/src/frontend/langs/en-US.json +++ b/src/frontend/langs/en-US.json @@ -164,7 +164,8 @@ "tokenRequired": "Token is required.", "invalidParameter": "Invalid parameter.", "notAuthorized": "Not authorized.", - "noNewUserAllowed": "You cannot signup to this service for now.", + "noNewUserAllowed": "You cannot signup on this service for now.", + "notWhitelisted": "Your instance is not whitelisted.", "hostNotFound": "Could not connect to the instance. Make sure that the host name is correct and the instance is live.", "other": "None" }, diff --git a/src/frontend/langs/ko-KR.json b/src/frontend/langs/ko-KR.json index 470cb8c..21b6778 100644 --- a/src/frontend/langs/ko-KR.json +++ b/src/frontend/langs/ko-KR.json @@ -165,6 +165,7 @@ "invalidParameter": "잘못된 요청 내용입니다. 값을 확인 후 다시 시도하세요.", "notAuthorized": "이 리소스에 접근할 권한이 없습니다.", "noNewUserAllowed": "현재 본 서비스에 신규 가입하실 수 없습니다.", + "notWhitelisted": "본 서비스의 접근 가능 목록에 등록되지 않은 인스턴스입니다.", "hostNotFound": "인스턴스에 접속할 수 없습니다. 입력한 인스턴스 주소가 올바른지, API 요청이 가능한지 확인해주세요.", "other": "알 수 없는 오류가 발생했습니다. Mastodon 인스턴스로 로그인을 시도했을 수 있습니다." },