diff --git a/frontend/src/api/auth/index.ts b/frontend/src/api/auth/index.ts index d5d4ef4e..c823ca28 100644 --- a/frontend/src/api/auth/index.ts +++ b/frontend/src/api/auth/index.ts @@ -36,6 +36,21 @@ export interface LoginResponse { created_at: string updated_at: string } + // active_tenant mirrors `tenant` for endpoints that distinguish home + // tenant from current tenant (e.g. /auth/register-by-invite). Only + // one of `tenant` / `active_tenant` is populated by any given endpoint. + active_tenant?: { + id: number + name: string + description?: string + api_key?: string + status?: string + business?: string + storage_quota?: number + storage_used?: number + created_at?: string + updated_at?: string + } token?: string refresh_token?: string } @@ -417,3 +432,59 @@ export async function validateToken(): Promise<{ success: boolean; valid?: boole + +// ---- share-link registration -------------------------------------------- + +// InviteLookup is the public projection of a share-link row used by +// /register?token=xxx — enough to render the registration page header +// ("X invited you to Y") without leaking sensitive inviter fields. +export interface InviteLookup { + tenant_id: number + tenant_name?: string + role: string + expires_at: string +} + +export interface InviteLookupResponse { + success: boolean + data?: InviteLookup + message?: string +} + +export interface RegisterByInviteRequest { + token: string + email: string + username: string + password: string +} + +/** + * Resolve a share-link token (no auth) into the context the + * registration page needs (tenant name, role, expiry). Returns 410 + * when the link is invalid / revoked / expired. + * + * Uses POST + body (rather than GET + path) so the plaintext token + * never appears in access logs, browser history, or tracing spans. + */ +export async function getInvitationByToken(token: string): Promise { + try { + const response = await post(`/api/v1/auth/invitations/lookup`, { token }) + return response as unknown as InviteLookupResponse + } catch (error: any) { + return { success: false, message: error.message || '' } + } +} + +/** + * Complete registration via a share-link token. The invitee supplies + * their own email — the token is the authorisation, not an identity + * lock. + */ +export async function registerByInvite(data: RegisterByInviteRequest): Promise { + try { + const response = await post('/api/v1/auth/register-by-invite', data) + return response as unknown as LoginResponse + } catch (error: any) { + return { success: false, message: error.message || t('error.auth.registerFailed') } + } +} diff --git a/frontend/src/api/tenant/invitations.ts b/frontend/src/api/tenant/invitations.ts index eda2aa2c..a17a2294 100644 --- a/frontend/src/api/tenant/invitations.ts +++ b/frontend/src/api/tenant/invitations.ts @@ -31,6 +31,17 @@ export interface TenantInvitation { expires_at: string responded_at?: string | null created_at: string + // invite_url is set on share-link rows that are still pending. The + // backend re-emits it on every list/get so Owners can copy the + // link on demand without "copy now or revoke" pressure. + invite_url?: string + // is_share_link distinguishes share-link rows (no specific invitee, + // multi-use, copyable URL) from per-user invitations. + is_share_link?: boolean + // accepted_count counts how many users have completed registration + // through this invitation. Surfaced in the management UI for + // share-link rows ("已加入 N 人"). + accepted_count?: number } export interface ListInvitationsResponse { @@ -191,3 +202,35 @@ export async function declineInvitation(invId: number): Promise `/api/v1/me/invitations/${invId}/decline`, )) as unknown as SimpleResponse } + +// ---- share-link API ---------------------------------------------------- + +export interface CreateInviteLinkRequest { + role: TenantRole + message?: string +} + +export interface CreateInviteLinkResponse { + success: boolean + data?: TenantInvitation + message?: string +} + +/** + * Generate a multi-use share-link invitation for the tenant. The + * returned row carries `invite_url` (composed from the persisted + * plaintext token) which the SPA copies into clipboards. The link + * stays valid until expiry or revocation; revoking is the same DELETE + * as a per-user invitation. + * + * Backend: POST /api/v1/tenants/:id/invite-links (Owner+). + */ +export async function createInviteLink( + tenantId: number, + body: CreateInviteLinkRequest, +): Promise { + return (await post( + `/api/v1/tenants/${tenantId}/invite-links`, + body, + )) as unknown as CreateInviteLinkResponse +} diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 084d1230..28a1e690 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1305,6 +1305,32 @@ export default { chunkOverlapDesc: 'Number of characters overlapping between adjacent chunks. Helps maintain context at chunk boundaries.', selectRelationType: 'Select relation type' }, + inviteRegister: { + bannerTitle: 'You have been invited to join "{tenant}"', + bannerHint: 'Fill in the details below to register. You will join the team automatically once registration completes.', + loading: 'Verifying invitation link…', + invalidTitle: 'Invitation link is invalid or revoked', + invalidBody: 'Ask your inviter to send a new link, or sign in with an existing account.', + backToLogin: 'Back to login', + title: 'Complete registration', + subtitle: "You've been invited to join “{tenant}”", + email: 'Email', + emailPlaceholder: 'your@example.com', + emailHint: 'Use any email address you control.', + emailInvalid: 'Please enter a valid email address', + username: 'Display name', + usernamePlaceholder: 'Enter your display name', + password: 'Set a password', + passwordPlaceholder: 'At least 6 characters', + confirmPassword: 'Confirm password', + submit: 'Complete registration', + submitting: 'Submitting…', + success: 'Registration successful — entering workspace…', + failed: 'Registration failed; please try again later', + usernameRequired: 'Display name is required', + passwordTooShort: 'Password must be at least 6 characters', + passwordMismatch: 'Passwords do not match', + }, auth: { login: 'Login', logout: 'Logout', @@ -4781,6 +4807,23 @@ export default { confirmInviteBody: 'Send an invitation to {email} (role: {role}). They will join the tenant only after accepting.', confirmSend: 'Send', + copyLink: 'Copy invite link', + copied: 'Copied to clipboard', + copyFailed: 'Copy failed; please select the text manually', + shareLink: { + button: 'Generate share link', + label: 'Share link', + cellTitle: 'Invite via link', + cellAccepted: '{count} joined', + cellEmpty: 'No one has joined yet', + dialogTitle: 'Generate share invitation link', + description: + "Generate a multi-use registration link you can drop in a group chat. Anyone who opens it registers with their own email and joins this workspace. Expires in {days} days, or revoke it any time from the list.", + generate: 'Generate link', + resultTitle: 'Invitation link ready', + resultBody: "Copy the link below and share it via any private channel. It's also saved in the list — you can re-copy or revoke it later.", + revokeConfirm: "Revoking will block anyone who hasn't registered yet from using this link. Generate a new one to re-share.", + }, revoke: { button: 'Revoke', confirmTitle: 'Revoke invitation?', @@ -4799,6 +4842,7 @@ export default { }, status: { pending: 'Pending', + shareLinkActive: 'Active', accepted: 'Accepted', declined: 'Declined', revoked: 'Revoked', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index c1b2fb85..5a1ebf36 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -1162,6 +1162,32 @@ export default { "인접 청크 간의 중복 문자 수입니다. 청크 경계에서 컨텍스트를 유지하는 데 도움이 됩니다.", selectRelationType: "관계 유형 선택", }, + inviteRegister: { + bannerTitle: "「{tenant}」에 초대되었습니다", + bannerHint: "아래 정보를 입력해 가입을 완료하세요. 등록이 끝나면 자동으로 팀에 합류합니다.", + loading: "초대 링크를 확인하는 중…", + invalidTitle: "초대 링크가 유효하지 않거나 취소되었습니다", + invalidBody: "초대한 분께 새 링크를 요청하거나 기존 계정으로 로그인하세요.", + backToLogin: "로그인으로 돌아가기", + title: "가입 완료", + subtitle: "「{tenant}」에 초대되었습니다", + email: "이메일", + emailPlaceholder: "your@example.com", + emailHint: "본인이 사용하는 이메일이면 됩니다.", + emailInvalid: "유효한 이메일을 입력해 주세요", + username: "표시 이름", + usernamePlaceholder: "이름을 입력하세요", + password: "비밀번호 설정", + passwordPlaceholder: "최소 6자 이상", + confirmPassword: "비밀번호 확인", + submit: "가입 완료", + submitting: "전송 중…", + success: "가입 완료, 워크스페이스로 이동합니다…", + failed: "가입에 실패했습니다. 잠시 후 다시 시도해 주세요", + usernameRequired: "이름을 입력하세요", + passwordTooShort: "비밀번호는 최소 6자 이상이어야 합니다", + passwordMismatch: "두 비밀번호가 일치하지 않습니다", + }, auth: { login: "로그인", logout: "로그아웃", @@ -4839,6 +4865,23 @@ export default { confirmInviteTitle: "초대를 보내시겠습니까?", confirmInviteBody: "{email}에게 초대를 보냅니다(역할: {role}). 수락 후 멤버가 됩니다.", confirmSend: "보내기", + copyLink: "초대 링크 복사", + copied: "클립보드에 복사됨", + copyFailed: "복사 실패. 직접 선택해 주세요", + shareLink: { + button: "공유 링크 생성", + label: "공유 링크", + cellTitle: "링크로 초대", + cellAccepted: "{count}명 가입함", + cellEmpty: "아직 가입한 사람이 없습니다", + dialogTitle: "공유 초대 링크 생성", + description: + "여러 명이 사용할 수 있는 가입 링크를 생성합니다. 받은 사람이 자신의 이메일로 가입하고 이 워크스페이스에 합류합니다. {days}일 후 만료되며, 목록에서 언제든지 취소할 수 있습니다.", + generate: "링크 생성", + resultTitle: "초대 링크가 생성되었습니다", + resultBody: "아래 링크를 복사해 비공개 채널로 전달하세요. 목록에도 저장되어 다시 복사하거나 취소할 수 있습니다.", + revokeConfirm: "취소 후에는 미가입자가 이 링크를 사용할 수 없습니다. 다시 발급하려면 새 링크를 생성하세요.", + }, revoke: { button: "취소", confirmTitle: "초대를 취소하시겠습니까?", @@ -4856,6 +4899,7 @@ export default { }, status: { pending: "대기 중", + shareLinkActive: "활성", accepted: "수락됨", declined: "거절됨", revoked: "취소됨", diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index a39061a5..5ad87151 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -1157,6 +1157,32 @@ export default { chunkOverlapDesc: "相邻块之间重叠的字符数。有助于保持块边界处的上下文。", selectRelationType: "选择关系类型", }, + inviteRegister: { + bannerTitle: "您被邀请加入「{tenant}」", + bannerHint: "填写下方信息完成注册,注册成功后将自动加入该团队。", + loading: "正在校验邀请链接…", + invalidTitle: "邀请链接无效或已撤销", + invalidBody: "请联系邀请人重新发送链接,或前往登录使用现有账号。", + backToLogin: "返回登录", + title: "完成注册", + subtitle: "您被邀请加入「{tenant}」", + email: "邮箱", + emailPlaceholder: "your@example.com", + emailHint: "用您自己的邮箱注册即可。", + emailInvalid: "请输入有效的邮箱地址", + username: "姓名", + usernamePlaceholder: "请输入您的姓名", + password: "设置密码", + passwordPlaceholder: "至少 6 位", + confirmPassword: "确认密码", + submit: "完成注册", + submitting: "提交中…", + success: "注册成功,正在进入工作空间…", + failed: "注册失败,请稍后重试", + usernameRequired: "请输入姓名", + passwordTooShort: "密码至少 6 位", + passwordMismatch: "两次输入的密码不一致", + }, auth: { login: "登录", logout: "退出", @@ -4773,6 +4799,23 @@ export default { confirmInviteBody: "将向 {email} 发出加入邀请(角色:{role})。TA 在站内接受后才会成为成员。", confirmSend: "发送", + copyLink: "复制邀请链接", + copied: "已复制到剪贴板", + copyFailed: "复制失败,请手动选中文本", + shareLink: { + button: "生成共享链接", + label: "共享链接", + cellTitle: "通过链接邀请", + cellAccepted: "已加入 {count} 人", + cellEmpty: "尚无成员加入", + dialogTitle: "生成共享邀请链接", + description: + "生成一条多人可用的注册链接,发到群里就行;谁打开都能用自己的邮箱注册并加入当前空间。链接 {days} 天后过期,或随时可在列表中撤销。", + generate: "生成链接", + resultTitle: "邀请链接已生成", + resultBody: "复制下方链接,通过任意私密渠道发给被邀请人。链接也会保存在下方列表中,随时可以重新复制或撤销。", + revokeConfirm: "撤销后,所有还未注册的人都无法再使用此链接;如需重发请生成新链接。", + }, revoke: { button: "撤销", confirmTitle: "确认撤销邀请?", @@ -4791,6 +4834,7 @@ export default { }, status: { pending: "待接受", + shareLinkActive: "生效中", accepted: "已接受", declined: "已拒绝", revoked: "已撤销", diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 141bcc98..c6c3420b 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -51,6 +51,17 @@ const router = createRouter({ component: () => import("../views/auth/Login.vue"), meta: { requiresAuth: false, requiresInit: false } }, + { + path: "/register", + name: "registerByInvite", + // Share-link landing page reuses the Login form: the same Vue + // component renders both modes and detects ?token=xxx on mount + // to switch into invite-register flow. Avoids a parallel page + // that would duplicate the OIDC / language-switch / styling + // surface for one extra field. + component: () => import("../views/auth/Login.vue"), + meta: { requiresAuth: false, requiresInit: false } + }, { path: "/join", name: "joinOrganization", diff --git a/frontend/src/views/auth/Login.vue b/frontend/src/views/auth/Login.vue index f3caed97..995a1482 100755 --- a/frontend/src/views/auth/Login.vue +++ b/frontend/src/views/auth/Login.vue @@ -272,8 +272,29 @@ - -
+ +
+ +
+ +
+
+ {{ $t('inviteRegister.bannerTitle', { tenant: inviteLookup.tenant_name || '' }) }} +
+
+ {{ $t('inviteRegister.bannerHint') }} +
+
+
+
+ {{ inviteLookupError }} +

{{ $t('auth.createAccount') }}

{{ $t('auth.registerSubtitle') }}

@@ -370,7 +391,7 @@