0
0
Fork 0

fix: separate whitelist and no new user

This commit is contained in:
아르페 2024-02-10 00:13:06 +09:00
parent 9f4b54f53b
commit 31ee293b7a
No known key found for this signature in database
GPG key ID: B1EFBBF5C93FF78F
5 changed files with 12 additions and 3 deletions

View file

@ -13,7 +13,8 @@
"admin": { "admin": {
"username": "your_user_name", "username": "your_user_name",
"host": "your-instance-host" "host": "your-instance-host"
} },
"noNewUserAllowed": false,
"whitelist": { "whitelist": {
"enabled": false, "enabled": false,
"instances": [ "instances": [

View file

@ -180,11 +180,16 @@ router.get('(.*)', async (ctx) => {
async function login(ctx: Context, user: Record<string, unknown>, host: string, token: string) { async function login(ctx: Context, user: Record<string, unknown>, host: string, token: string) {
const isNewcomer = !(await getUser(user.username as string, host)); 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); await die(ctx, 'noNewUserAllowed', 403);
return; return;
} }
if (config.whitelist.enabled && !config.whitelist.instances.includes(host)) {
await die(ctx, 'notWhitelisted', 403);
return;
}
await upsertUser(user.username as string, host, token); await upsertUser(user.username as string, host, token);
const u = await getUser(user.username as string, host); const u = await getUser(user.username as string, host);

View file

@ -8,6 +8,7 @@ export const errorCodes = [
'hostNotFound', 'hostNotFound',
'invalidHostFormat', 'invalidHostFormat',
'noNewUserAllowed', 'noNewUserAllowed',
'notWhitelisted',
'other', 'other',
] as const; ] as const;

View file

@ -164,7 +164,8 @@
"tokenRequired": "Token is required.", "tokenRequired": "Token is required.",
"invalidParameter": "Invalid parameter.", "invalidParameter": "Invalid parameter.",
"notAuthorized": "Not authorized.", "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.", "hostNotFound": "Could not connect to the instance. Make sure that the host name is correct and the instance is live.",
"other": "None" "other": "None"
}, },

View file

@ -165,6 +165,7 @@
"invalidParameter": "잘못된 요청 내용입니다. 값을 확인 후 다시 시도하세요.", "invalidParameter": "잘못된 요청 내용입니다. 값을 확인 후 다시 시도하세요.",
"notAuthorized": "이 리소스에 접근할 권한이 없습니다.", "notAuthorized": "이 리소스에 접근할 권한이 없습니다.",
"noNewUserAllowed": "현재 본 서비스에 신규 가입하실 수 없습니다.", "noNewUserAllowed": "현재 본 서비스에 신규 가입하실 수 없습니다.",
"notWhitelisted": "본 서비스의 접근 가능 목록에 등록되지 않은 인스턴스입니다.",
"hostNotFound": "인스턴스에 접속할 수 없습니다. 입력한 인스턴스 주소가 올바른지, API 요청이 가능한지 확인해주세요.", "hostNotFound": "인스턴스에 접속할 수 없습니다. 입력한 인스턴스 주소가 올바른지, API 요청이 가능한지 확인해주세요.",
"other": "알 수 없는 오류가 발생했습니다. Mastodon 인스턴스로 로그인을 시도했을 수 있습니다." "other": "알 수 없는 오류가 발생했습니다. Mastodon 인스턴스로 로그인을 시도했을 수 있습니다."
}, },