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": {
"username": "your_user_name",
"host": "your-instance-host"
}
},
"noNewUserAllowed": false,
"whitelist": {
"enabled": false,
"instances": [

View File

@ -180,11 +180,16 @@ router.get('(.*)', async (ctx) => {
async function login(ctx: Context, user: Record<string, unknown>, 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);

View File

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

View File

@ -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"
},

View File

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