Fix recorder finalize path and add invite-gated login
这个提交包含在:
15
server/db.ts
15
server/db.ts
@@ -82,7 +82,16 @@ export async function getUserByUsername(username: string) {
|
||||
return userResult.length > 0 ? userResult[0] : undefined;
|
||||
}
|
||||
|
||||
export async function createUsernameAccount(username: string): Promise<{ user: typeof users.$inferSelect; isNew: boolean }> {
|
||||
export function isValidRegistrationInvite(inviteCode?: string | null) {
|
||||
const expected = ENV.registrationInviteCode.trim();
|
||||
if (!expected) return true;
|
||||
return (inviteCode ?? "").trim() === expected;
|
||||
}
|
||||
|
||||
export async function createUsernameAccount(
|
||||
username: string,
|
||||
inviteCode?: string,
|
||||
): Promise<{ user: typeof users.$inferSelect; isNew: boolean }> {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
|
||||
@@ -97,6 +106,10 @@ export async function createUsernameAccount(username: string): Promise<{ user: t
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValidRegistrationInvite(inviteCode)) {
|
||||
throw new Error("新用户注册需要正确的邀请码");
|
||||
}
|
||||
|
||||
// Create new user with username as openId
|
||||
const openId = `username_${username}_${Date.now()}`;
|
||||
await db.insert(users).values({
|
||||
|
||||
在新工单中引用
屏蔽一个用户