diff --git a/Dockerfile b/Dockerfile index cf4dc5ad..513e1be5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -80,6 +80,11 @@ USER root COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# Expose "bun index.js" as "shumai" CLI command (and alias "shuami") +RUN printf '#!/bin/sh\nexec bun /app/index.js "$@"\n' > /usr/local/bin/shumai \ + && chmod +x /usr/local/bin/shumai \ + && ln -s /usr/local/bin/shumai /usr/local/bin/shuami + ENTRYPOINT ["docker-entrypoint.sh"] # Default command: run migrations and start API server diff --git a/apps/web/e2e/README.md b/apps/web/e2e/README.md index a23474d5..970582d8 100644 --- a/apps/web/e2e/README.md +++ b/apps/web/e2e/README.md @@ -56,6 +56,8 @@ apps/web/e2e/ |---|---| | Sign up as the first user and become the team owner | `tests/auth/signup.spec.ts` | | Log in with existing credentials | `tests/auth/login.spec.ts` | +| Show error when accessing reset-password page without token | `tests/auth/reset-password.spec.ts` | +| Reset password with valid token and allow logging in with new password | `tests/auth/reset-password.spec.ts` | ### team | Test | File | diff --git a/apps/web/e2e/tests/auth/reset-password.spec.ts b/apps/web/e2e/tests/auth/reset-password.spec.ts new file mode 100644 index 00000000..70ab2e88 --- /dev/null +++ b/apps/web/e2e/tests/auth/reset-password.spec.ts @@ -0,0 +1,63 @@ +import { expect, test } from '../../fixtures' +import { apiSignup, E2E_PASSWORD, uniqueEmail } from '../../helpers/auth' +import { loginViaUi } from '../../helpers/ui' + +test('should show error when accessing reset-password page without token', async ({ page }) => { + await page.goto('/reset-password') + await expect(page.getByText('Invalid or missing reset token.')).toBeVisible() + await expect(page.getByRole('button', { name: 'Go to Login' })).toBeVisible() +}) + +test('should reset password with valid token and allow logging in with new password', async ({ + page, + request, + prisma, +}) => { + const email = uniqueEmail('reset-pw') + const oldPassword = E2E_PASSWORD + const newPassword = 'newSecretPassword123' + + // 1. Seed user + await apiSignup(request, email, oldPassword) + + // 2. Request password reset via API + const resetRes = await request.post('/api/auth/request-password-reset', { + data: { + email, + redirectTo: '/reset-password', + }, + }) + expect(resetRes.ok()).toBe(true) + + // Retrieve the generated verification token from DB + const verification = await prisma.verification.findFirst({ + where: { + identifier: { startsWith: 'reset-password:' }, + }, + orderBy: { createdAt: 'desc' }, + }) + expect(verification).not.toBeNull() + const token = verification!.identifier.replace('reset-password:', '') + + // 3. Open reset password page with token + await page.goto(`/reset-password?token=${token}`) + + // 4. Fill in new password and confirmation + await page.locator('input#password').fill(newPassword) + await page.locator('input#confirmPassword').fill(newPassword) + + // 5. Submit form + await page.getByRole('button', { name: 'Reset Password' }).click() + + // 6. Verify success state + await expect(page.getByText('Password reset successfully!')).toBeVisible() + + // 7. Click Go to Login + await page.getByRole('button', { name: 'Go to Login' }).click() + await expect(page).toHaveURL('/login') + + // 8. Log in with the new password + await loginViaUi(page, email, newPassword) + await expect(page).toHaveURL(/\/teams\/[^/]+/) + await expect(page.getByRole('heading', { name: 'Projects' })).toBeVisible() +}) diff --git a/apps/web/src/index.ts b/apps/web/src/index.ts index 5b7a391f..54328b36 100644 --- a/apps/web/src/index.ts +++ b/apps/web/src/index.ts @@ -13,12 +13,37 @@ import { initTranscodeWorkflows } from '@shumai/transcode' import { workflowService } from '@shumai/workflow-core' import { handleDaemonCommands } from '@shumai/core/src/utils/daemon' +import { authService } from '@shumai/core/src/auth/auth' if (process.argv.includes('--check')) { console.log('✅ Web app evaluated successfully!') process.exit(0) } +const cliArgs = process.argv.slice(2) +const resetCmdIndex = cliArgs.findIndex( + (arg) => arg === 'reset-password' || arg === 'reset-passowrd', +) + +if (resetCmdIndex !== -1) { + const email = cliArgs[resetCmdIndex + 1] + if (!email || email.startsWith('-')) { + console.error('Error: Please provide a valid email address.') + console.error('Usage: shumai reset-password ') + process.exit(1) + } + + try { + const link = await authService.generatePasswordResetLink(email) + console.log(link) + process.exit(0) + } catch (err: unknown) { + const message = err instanceof Error ? err.message : 'Unknown error' + console.error(`Error: ${message}`) + process.exit(1) + } +} + async function run() { // Initialize workflows and activities for local executor mode initAgentWorkflows() diff --git a/docs/docs.json b/docs/docs.json index faa35e87..ff546814 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -52,7 +52,11 @@ }, { "group": "Team Settings", - "pages": ["using-shumai/transcode-settings", "using-shumai/quotas-settings"] + "pages": [ + "using-shumai/transcode-settings", + "using-shumai/quotas-settings", + "using-shumai/password-reset" + ] }, { "group": "Configuration", diff --git a/docs/using-shumai/password-reset.mdx b/docs/using-shumai/password-reset.mdx new file mode 100644 index 00000000..6782c413 --- /dev/null +++ b/docs/using-shumai/password-reset.mdx @@ -0,0 +1,60 @@ +--- +title: Password Reset +description: How administrators generate secure password reset links for team members. +--- + +Because Shumai does not require an external email delivery service (SMTP) to be configured for standard self-hosted deployments, password resets are initiated securely by an administrator using the Shumai CLI. + +--- + +## Overview + +When a user forgets their password, an administrator can generate a one-time password reset link directly from the command line. + +- **Link Expiration**: The generated password reset link is valid for **1 hour** (`3600 seconds`). +- **One-Time Use**: Once used, the token is permanently invalidated. +- **Session Revocation**: When a user resets their password, all existing active sessions for that account are automatically revoked across all devices. +- **Latest Link Validity**: Generating a new reset link for a user immediately supersedes any previously generated pending links. + +--- + +## Generating a Password Reset Link + +### Running on Local Host / Server + +Run the `reset-password` subcommand from your Shumai installation directory: + +```bash +shumai reset-password +``` + +_(Alternatively, `bun apps/web/src/index.ts reset-password `)_ + +**Example Output:** + +```text +http://localhost:3000/reset-password?token=bb3xg4uO3cwN0FQv4cgUK6Hh +``` + +### Running inside Docker + +If Shumai is running inside a Docker container, execute the command using `docker exec`: + +```bash +docker exec -it shumai reset-password +``` + +> [!TIP] +> Both `shumai` and the common alias `shuami` (e.g. `shuami reset-password `) are supported. + +> [!NOTE] +> For remote servers or production deployments, ensure `BETTER_AUTH_URL` is set in your environment (e.g., `BETTER_AUTH_URL=https://shumai.example.com`) so the CLI generates the reset link with your public domain instead of `localhost`. + +--- + +## Member Reset Experience + +1. The administrator sends the generated URL to the team member via their preferred secure communication channel. +2. The user opens the link in their browser. +3. The user inputs their **New Password** and **Confirm Password** (minimum 3 characters). +4. Upon clicking **Reset Password**, the password is securely updated, all previous active sessions are invalidated, and the user is redirected to `/login` to sign in. diff --git a/packages/core/src/auth/auth.test.ts b/packages/core/src/auth/auth.test.ts index 2e5d57f4..8a7399ef 100644 --- a/packages/core/src/auth/auth.test.ts +++ b/packages/core/src/auth/auth.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' -import { auth } from './auth' +import { auth, authService } from './auth' import { userMetadataService } from '../user-metadata/user-metadata' import { teamService } from '@shumai/core/src/team/team' @@ -93,3 +93,214 @@ describe('Auth Signup Locale Hook', () => { } }) }) + +describe('AuthService Password Reset', () => { + setupTestDbHooks() + + beforeEach(() => { + vi.spyOn(teamService, 'getSignupInfo').mockResolvedValue({ + initialized: false, + demoMode: false, + userCount: 1, + }) + }) + + it('should throw error when generating reset link for non-existent user', async () => { + await expect(authService.generatePasswordResetLink('nonexistent@example.com')).rejects.toThrow( + 'User with email "nonexistent@example.com" not found', + ) + }) + + it('should generate a valid reset link and invalidate previous pending tokens', async () => { + const email = `reset-user-${Date.now()}@example.com` + const signUpRes = await auth.api.signUpEmail({ + headers: new Headers(), + body: { + email, + password: 'initialPassword123', + name: 'Reset User', + }, + }) + const userId = signUpRes.user.id + + const firstLink = await authService.generatePasswordResetLink(email) + expect(firstLink).toContain('/reset-password?token=') + + const firstToken = new URL(firstLink).searchParams.get('token')! + expect(firstToken).toBeTruthy() + + // Check that verification record exists with identifier: reset-password: and value: userId + const firstVerification = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${firstToken}` }, + }) + expect(firstVerification).not.toBeNull() + expect(firstVerification?.value).toBe(userId) + + // Generating a second link should produce a new token and invalidate the first token + const secondLink = await authService.generatePasswordResetLink(email) + const secondToken = new URL(secondLink).searchParams.get('token')! + expect(secondToken).not.toBe(firstToken) + + const newVerification = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${secondToken}` }, + }) + expect(newVerification).not.toBeNull() + expect(newVerification?.value).toBe(userId) + + // The first token's verification record must have been deleted + const oldVerification = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${firstToken}` }, + }) + expect(oldVerification).toBeNull() + + // First token must fail to reset password + await expect( + authService.resetPassword(firstToken, 'newPasswordFromFirstToken'), + ).rejects.toThrow() + + // Second token must succeed + const resetRes = await authService.resetPassword(secondToken, 'newPasswordFromSecondToken') + expect(resetRes.success).toBe(true) + }) + + it('should reset password with valid token and revoke active sessions', async () => { + const email = `reset-valid-${Date.now()}@example.com` + const signUpRes = await auth.api.signUpEmail({ + headers: new Headers(), + body: { + email, + password: 'oldPassword123', + name: 'Valid Reset User', + }, + }) + + const userId = signUpRes.user.id + + // Create an active session + await prisma.session.create({ + data: { + userId, + token: `session-${Date.now()}`, + expiresAt: new Date(Date.now() + 86400 * 1000), + }, + }) + + const activeSessionsBefore = await prisma.session.findMany({ + where: { userId }, + }) + expect(activeSessionsBefore.length).toBeGreaterThan(0) + + // Generate reset link + const link = await authService.generatePasswordResetLink(email) + const token = new URL(link).searchParams.get('token')! + + // Reset password + const result = await authService.resetPassword(token, 'newPassword456') + expect(result.success).toBe(true) + + // Verify active sessions are revoked + const activeSessionsAfter = await prisma.session.findMany({ + where: { userId }, + }) + expect(activeSessionsAfter.length).toBe(0) + + // Verify token was deleted + const usedToken = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${token}` }, + }) + expect(usedToken).toBeNull() + + // Verify user password was updated to new password + const account = await prisma.account.findFirst({ + where: { userId, providerId: 'credential' }, + }) + expect(account).toBeDefined() + expect(account?.password).toBeTruthy() + + const { verifyPassword } = await import('better-auth/crypto') + const isNewValid = await verifyPassword({ + hash: account!.password!, + password: 'newPassword456', + }) + expect(isNewValid).toBe(true) + + const isOldValid = await verifyPassword({ + hash: account!.password!, + password: 'oldPassword123', + }) + expect(isOldValid).toBe(false) + }) + + it('should reject expired or invalid token', async () => { + const email = `reset-expired-${Date.now()}@example.com` + const user = await prisma.user.create({ + data: { + email, + name: 'Expired User', + }, + }) + + // Create expired token fixture with identifier: reset-password: and value: userId + const token = 'expired-token-123' + await prisma.verification.create({ + data: { + identifier: `reset-password:${token}`, + value: user.id, + expiresAt: new Date(Date.now() - 1000), // Expired 1 second ago + }, + }) + + await expect(authService.resetPassword(token, 'newPassword123')).rejects.toThrow() + + // Non-existent token + await expect( + authService.resetPassword('non-existent-token', 'newPassword123'), + ).rejects.toThrow() + }) + + it('should handle concurrent link generation for different users without crosstalk', async () => { + const emailA = `concurrent-a-${Date.now()}@example.com` + const emailB = `concurrent-b-${Date.now()}@example.com` + + const [resA, resB] = await Promise.all([ + auth.api.signUpEmail({ + headers: new Headers(), + body: { email: emailA, password: 'passwordA123', name: 'User A' }, + }), + auth.api.signUpEmail({ + headers: new Headers(), + body: { email: emailB, password: 'passwordB123', name: 'User B' }, + }), + ]) + + const [linkA, linkB] = await Promise.all([ + authService.generatePasswordResetLink(emailA), + authService.generatePasswordResetLink(emailB), + ]) + + const tokenA = new URL(linkA).searchParams.get('token')! + const tokenB = new URL(linkB).searchParams.get('token')! + expect(tokenA).toBeTruthy() + expect(tokenB).toBeTruthy() + expect(tokenA).not.toBe(tokenB) + + const verificationA = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${tokenA}` }, + }) + const verificationB = await prisma.verification.findFirst({ + where: { identifier: `reset-password:${tokenB}` }, + }) + + expect(verificationA?.value).toBe(resA.user.id) + expect(verificationB?.value).toBe(resB.user.id) + + // Reset both passwords concurrently + const [resetResA, resetResB] = await Promise.all([ + authService.resetPassword(tokenA, 'newPasswordA123'), + authService.resetPassword(tokenB, 'newPasswordB123'), + ]) + + expect(resetResA.success).toBe(true) + expect(resetResB.success).toBe(true) + }) +}) diff --git a/packages/core/src/auth/auth.ts b/packages/core/src/auth/auth.ts index 3de07d48..8bdc01c9 100644 --- a/packages/core/src/auth/auth.ts +++ b/packages/core/src/auth/auth.ts @@ -1,3 +1,4 @@ +import { AsyncLocalStorage } from 'node:async_hooks' import { betterAuth } from 'better-auth' import { prismaAdapter } from 'better-auth/adapters/prisma' import { prisma } from '@shumai/db' @@ -6,6 +7,13 @@ import { inviteService } from '@shumai/core/src/invite/invite' import { createAuthMiddleware } from 'better-auth/api' import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata' +interface GeneratedResetLink { + url: string + token: string +} + +const resetLinkStorage = new AsyncLocalStorage() + export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'postgresql', @@ -13,6 +21,15 @@ export const auth = betterAuth({ emailAndPassword: { enabled: true, minPasswordLength: 3, + revokeSessionsOnPasswordReset: true, + resetPasswordTokenExpiresIn: 3600, + sendResetPassword: async ({ url, token }) => { + const store = resetLinkStorage.getStore() + if (store) { + store.url = url + store.token = token + } + }, }, secret: process.env.BETTER_AUTH_SECRET, // eslint-disable-next-line @typescript-eslint/naming-convention @@ -122,3 +139,82 @@ export const auth = betterAuth({ }), }, }) + +export class AuthService { + constructor(private readonly prismaClient: typeof prisma = prisma) {} + + async generatePasswordResetLink(email: string): Promise { + const user = await this.prismaClient.user.findUnique({ + where: { email }, + }) + + if (!user) { + throw new Error(`User with email "${email}" not found`) + } + + const context: GeneratedResetLink = { url: '', token: '' } + await resetLinkStorage.run(context, async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const res = await (auth.api.requestPasswordReset as any)({ + headers: new Headers(), + body: { + email, + redirectTo: '/reset-password', + }, + }) + + if (res?.error) { + throw new Error(res.error.message || 'Failed to generate reset link') + } + }) + + if (context.token) { + // Invalidate any other pending reset tokens for this user + await this.prismaClient.verification.deleteMany({ + where: { + value: user.id, + identifier: { + startsWith: 'reset-password:', + not: `reset-password:${context.token}`, + }, + }, + }) + + const rawBaseUrl = + process.env.BETTER_AUTH_URL || + `http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}` + const baseUrl = rawBaseUrl.replace(/\/$/, '') + return `${baseUrl}/reset-password?token=${context.token}` + } + + throw new Error('Failed to generate reset link') + } + + async resetPassword(token: string, newPassword: string): Promise<{ success: boolean }> { + if (!token || !token.trim()) { + throw new Error('Token is required') + } + + if (!newPassword || newPassword.length < 3) { + throw new Error('Password must be at least 3 characters') + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const res = await (auth.api.resetPassword as any)({ + headers: new Headers(), + body: { + token, + newPassword, + password: newPassword, + }, + }) + + if (res?.error) { + throw new Error(res.error.message || 'Failed to reset password') + } + + return { success: true } + } +} + +export const authService = new AuthService() diff --git a/packages/webui/e2e/tests/audio-playback.spec.ts b/packages/webui/e2e/tests/audio-playback.spec.ts index c9a39467..56c674f8 100644 --- a/packages/webui/e2e/tests/audio-playback.spec.ts +++ b/packages/webui/e2e/tests/audio-playback.spec.ts @@ -22,13 +22,14 @@ test.describe('audio player e2e', () => { await vp.clickPlayToggle() await expect.poll(() => vp.isPaused(), { timeout: 5_000 }).toBe(false) - // Wait for 300ms. If the playhead froze (which happened under the bug where + // Wait for playhead to advance. If the playhead froze (which happened under the bug where // it waited 1000ms for rVFC grace period), readoutFrame would still be 0. // With the fix, the playhead should advance immediately. - await page.waitForTimeout(300) + await expect + .poll(async () => (await vp.snapshot()).readoutFrame, { timeout: 5_000 }) + .toBeGreaterThan(0) const afterPlay = await vp.snapshot() - expect(afterPlay.readoutFrame).toBeGreaterThan(0) expect(afterPlay.currentTime).toBeGreaterThan(0) }) }) diff --git a/packages/webui/lib/auth-client.ts b/packages/webui/lib/auth-client.ts index f1984697..54f7ab6d 100644 --- a/packages/webui/lib/auth-client.ts +++ b/packages/webui/lib/auth-client.ts @@ -5,4 +5,4 @@ export const authClient = createAuthClient({ baseURL: window.location.origin, }) -export const { signIn, signUp, useSession, signOut } = authClient +export const { signIn, signUp, useSession, signOut, resetPassword } = authClient diff --git a/packages/webui/messages/en.json b/packages/webui/messages/en.json index aee46b24..43f98833 100644 --- a/packages/webui/messages/en.json +++ b/packages/webui/messages/en.json @@ -51,6 +51,19 @@ "first_user_notice": "You will be the owner of the default workspace as the first user!", "password_min_placeholder": "At least 3 characters", "invite_join_message": "{inviterName} invited you to join {targetName} as {role}.", + "reset_password": "Reset Password", + "reset_password_subtitle": "Enter your new password below.", + "new_password": "New Password", + "confirm_password": "Confirm Password", + "new_password_placeholder": "Enter new password", + "confirm_password_placeholder": "Confirm new password", + "passwords_do_not_match": "Passwords do not match", + "resetting_password": "Resetting password...", + "password_reset_success": "Password reset successfully!", + "password_reset_success_description": "You will be redirected to the login page shortly.", + "invalid_reset_token": "Invalid or missing reset token.", + "invalid_reset_token_description": "Please contact your administrator to generate a new password reset link.", + "go_to_login": "Go to Login", "cancel": "Cancel", "create": "Create", diff --git a/packages/webui/messages/zh.json b/packages/webui/messages/zh.json index 12ee46c2..687ddacd 100644 --- a/packages/webui/messages/zh.json +++ b/packages/webui/messages/zh.json @@ -51,6 +51,19 @@ "first_user_notice": "作为第一位用户,您将成为默认工作空间的拥有者!", "password_min_placeholder": "至少 3 个字符", "invite_join_message": "{inviterName} 邀请您加入 {targetName},角色为 {role}。", + "reset_password": "重置密码", + "reset_password_subtitle": "请在下方输入您的新密码。", + "new_password": "新密码", + "confirm_password": "确认密码", + "new_password_placeholder": "输入新密码", + "confirm_password_placeholder": "确认新密码", + "passwords_do_not_match": "两次输入的密码不一致", + "resetting_password": "正在重置密码...", + "password_reset_success": "密码重置成功!", + "password_reset_success_description": "您将很快被重定向到登录页面。", + "invalid_reset_token": "无效或缺失的重置令牌。", + "invalid_reset_token_description": "请联系管理员生成新的密码重置链接。", + "go_to_login": "前往登录", "cancel": "取消", "create": "创建", diff --git a/packages/webui/paraglide/messages/_index.d.ts b/packages/webui/paraglide/messages/_index.d.ts index 5198b285..136e1d22 100644 --- a/packages/webui/paraglide/messages/_index.d.ts +++ b/packages/webui/paraglide/messages/_index.d.ts @@ -47,6 +47,19 @@ export * from "./registration_disabled_description.js"; export * from "./first_user_notice.js"; export * from "./password_min_placeholder.js"; export * from "./invite_join_message.js"; +export * from "./reset_password.js"; +export * from "./reset_password_subtitle.js"; +export * from "./new_password.js"; +export * from "./confirm_password.js"; +export * from "./new_password_placeholder.js"; +export * from "./confirm_password_placeholder.js"; +export * from "./passwords_do_not_match.js"; +export * from "./resetting_password.js"; +export * from "./password_reset_success.js"; +export * from "./password_reset_success_description.js"; +export * from "./invalid_reset_token.js"; +export * from "./invalid_reset_token_description.js"; +export * from "./go_to_login.js"; export * from "./cancel.js"; export * from "./create.js"; export * from "./save.js"; diff --git a/packages/webui/paraglide/messages/_index.js b/packages/webui/paraglide/messages/_index.js index 7c4b5211..72033641 100644 --- a/packages/webui/paraglide/messages/_index.js +++ b/packages/webui/paraglide/messages/_index.js @@ -49,6 +49,19 @@ export * from './registration_disabled_description.js' export * from './first_user_notice.js' export * from './password_min_placeholder.js' export * from './invite_join_message.js' +export * from './reset_password.js' +export * from './reset_password_subtitle.js' +export * from './new_password.js' +export * from './confirm_password.js' +export * from './new_password_placeholder.js' +export * from './confirm_password_placeholder.js' +export * from './passwords_do_not_match.js' +export * from './resetting_password.js' +export * from './password_reset_success.js' +export * from './password_reset_success_description.js' +export * from './invalid_reset_token.js' +export * from './invalid_reset_token_description.js' +export * from './go_to_login.js' export * from './cancel.js' export * from './create.js' export * from './save.js' diff --git a/packages/webui/paraglide/messages/confirm_password.d.ts b/packages/webui/paraglide/messages/confirm_password.d.ts new file mode 100644 index 00000000..a38efd46 --- /dev/null +++ b/packages/webui/paraglide/messages/confirm_password.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Confirm Password" | +* +* @param {Confirm_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const confirm_password: ((inputs?: Confirm_PasswordInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Confirm_PasswordInputs = {}; diff --git a/packages/webui/paraglide/messages/confirm_password.js b/packages/webui/paraglide/messages/confirm_password.js new file mode 100644 index 00000000..692b23e1 --- /dev/null +++ b/packages/webui/paraglide/messages/confirm_password.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Confirm_PasswordInputs */ + +const en_confirm_password = /** @type {(inputs: Confirm_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Confirm Password`) +}; + +const zh_confirm_password = /** @type {(inputs: Confirm_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`确认密码`) +}; + +/** +* | output | +* | --- | +* | "Confirm Password" | +* +* @param {Confirm_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const confirm_password = /** @type {((inputs?: Confirm_PasswordInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_confirm_password(inputs) + return zh_confirm_password(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/confirm_password_placeholder.d.ts b/packages/webui/paraglide/messages/confirm_password_placeholder.d.ts new file mode 100644 index 00000000..54b08a6b --- /dev/null +++ b/packages/webui/paraglide/messages/confirm_password_placeholder.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Confirm new password" | +* +* @param {Confirm_Password_PlaceholderInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const confirm_password_placeholder: ((inputs?: Confirm_Password_PlaceholderInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Confirm_Password_PlaceholderInputs = {}; diff --git a/packages/webui/paraglide/messages/confirm_password_placeholder.js b/packages/webui/paraglide/messages/confirm_password_placeholder.js new file mode 100644 index 00000000..6f183dbb --- /dev/null +++ b/packages/webui/paraglide/messages/confirm_password_placeholder.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Confirm_Password_PlaceholderInputs */ + +const en_confirm_password_placeholder = /** @type {(inputs: Confirm_Password_PlaceholderInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Confirm new password`) +}; + +const zh_confirm_password_placeholder = /** @type {(inputs: Confirm_Password_PlaceholderInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`确认新密码`) +}; + +/** +* | output | +* | --- | +* | "Confirm new password" | +* +* @param {Confirm_Password_PlaceholderInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const confirm_password_placeholder = /** @type {((inputs?: Confirm_Password_PlaceholderInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_confirm_password_placeholder(inputs) + return zh_confirm_password_placeholder(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/go_to_login.d.ts b/packages/webui/paraglide/messages/go_to_login.d.ts new file mode 100644 index 00000000..fa66f254 --- /dev/null +++ b/packages/webui/paraglide/messages/go_to_login.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Go to Login" | +* +* @param {Go_To_LoginInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const go_to_login: ((inputs?: Go_To_LoginInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Go_To_LoginInputs = {}; diff --git a/packages/webui/paraglide/messages/go_to_login.js b/packages/webui/paraglide/messages/go_to_login.js new file mode 100644 index 00000000..da94efd7 --- /dev/null +++ b/packages/webui/paraglide/messages/go_to_login.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Go_To_LoginInputs */ + +const en_go_to_login = /** @type {(inputs: Go_To_LoginInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Go to Login`) +}; + +const zh_go_to_login = /** @type {(inputs: Go_To_LoginInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`前往登录`) +}; + +/** +* | output | +* | --- | +* | "Go to Login" | +* +* @param {Go_To_LoginInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const go_to_login = /** @type {((inputs?: Go_To_LoginInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_go_to_login(inputs) + return zh_go_to_login(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/invalid_reset_token.d.ts b/packages/webui/paraglide/messages/invalid_reset_token.d.ts new file mode 100644 index 00000000..7c40195a --- /dev/null +++ b/packages/webui/paraglide/messages/invalid_reset_token.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Invalid or missing reset token." | +* +* @param {Invalid_Reset_TokenInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const invalid_reset_token: ((inputs?: Invalid_Reset_TokenInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Invalid_Reset_TokenInputs = {}; diff --git a/packages/webui/paraglide/messages/invalid_reset_token.js b/packages/webui/paraglide/messages/invalid_reset_token.js new file mode 100644 index 00000000..c9b99113 --- /dev/null +++ b/packages/webui/paraglide/messages/invalid_reset_token.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Invalid_Reset_TokenInputs */ + +const en_invalid_reset_token = /** @type {(inputs: Invalid_Reset_TokenInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Invalid or missing reset token.`) +}; + +const zh_invalid_reset_token = /** @type {(inputs: Invalid_Reset_TokenInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`无效或缺失的重置令牌。`) +}; + +/** +* | output | +* | --- | +* | "Invalid or missing reset token." | +* +* @param {Invalid_Reset_TokenInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const invalid_reset_token = /** @type {((inputs?: Invalid_Reset_TokenInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_invalid_reset_token(inputs) + return zh_invalid_reset_token(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/invalid_reset_token_description.d.ts b/packages/webui/paraglide/messages/invalid_reset_token_description.d.ts new file mode 100644 index 00000000..eb901088 --- /dev/null +++ b/packages/webui/paraglide/messages/invalid_reset_token_description.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Please contact your administrator to generate a new password reset link." | +* +* @param {Invalid_Reset_Token_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const invalid_reset_token_description: ((inputs?: Invalid_Reset_Token_DescriptionInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Invalid_Reset_Token_DescriptionInputs = {}; diff --git a/packages/webui/paraglide/messages/invalid_reset_token_description.js b/packages/webui/paraglide/messages/invalid_reset_token_description.js new file mode 100644 index 00000000..7641e10e --- /dev/null +++ b/packages/webui/paraglide/messages/invalid_reset_token_description.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Invalid_Reset_Token_DescriptionInputs */ + +const en_invalid_reset_token_description = /** @type {(inputs: Invalid_Reset_Token_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Please contact your administrator to generate a new password reset link.`) +}; + +const zh_invalid_reset_token_description = /** @type {(inputs: Invalid_Reset_Token_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`请联系管理员生成新的密码重置链接。`) +}; + +/** +* | output | +* | --- | +* | "Please contact your administrator to generate a new password reset link." | +* +* @param {Invalid_Reset_Token_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const invalid_reset_token_description = /** @type {((inputs?: Invalid_Reset_Token_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_invalid_reset_token_description(inputs) + return zh_invalid_reset_token_description(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/new_password.d.ts b/packages/webui/paraglide/messages/new_password.d.ts new file mode 100644 index 00000000..5cc1cceb --- /dev/null +++ b/packages/webui/paraglide/messages/new_password.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "New Password" | +* +* @param {New_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const new_password: ((inputs?: New_PasswordInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type New_PasswordInputs = {}; diff --git a/packages/webui/paraglide/messages/new_password.js b/packages/webui/paraglide/messages/new_password.js new file mode 100644 index 00000000..123c67b5 --- /dev/null +++ b/packages/webui/paraglide/messages/new_password.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} New_PasswordInputs */ + +const en_new_password = /** @type {(inputs: New_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`New Password`) +}; + +const zh_new_password = /** @type {(inputs: New_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`新密码`) +}; + +/** +* | output | +* | --- | +* | "New Password" | +* +* @param {New_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const new_password = /** @type {((inputs?: New_PasswordInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_new_password(inputs) + return zh_new_password(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/new_password_placeholder.d.ts b/packages/webui/paraglide/messages/new_password_placeholder.d.ts new file mode 100644 index 00000000..1fc3c0b1 --- /dev/null +++ b/packages/webui/paraglide/messages/new_password_placeholder.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Enter new password" | +* +* @param {New_Password_PlaceholderInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const new_password_placeholder: ((inputs?: New_Password_PlaceholderInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type New_Password_PlaceholderInputs = {}; diff --git a/packages/webui/paraglide/messages/new_password_placeholder.js b/packages/webui/paraglide/messages/new_password_placeholder.js new file mode 100644 index 00000000..946443a6 --- /dev/null +++ b/packages/webui/paraglide/messages/new_password_placeholder.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} New_Password_PlaceholderInputs */ + +const en_new_password_placeholder = /** @type {(inputs: New_Password_PlaceholderInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Enter new password`) +}; + +const zh_new_password_placeholder = /** @type {(inputs: New_Password_PlaceholderInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`输入新密码`) +}; + +/** +* | output | +* | --- | +* | "Enter new password" | +* +* @param {New_Password_PlaceholderInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const new_password_placeholder = /** @type {((inputs?: New_Password_PlaceholderInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_new_password_placeholder(inputs) + return zh_new_password_placeholder(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/password_reset_success.d.ts b/packages/webui/paraglide/messages/password_reset_success.d.ts new file mode 100644 index 00000000..2a4b47e6 --- /dev/null +++ b/packages/webui/paraglide/messages/password_reset_success.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Password reset successfully!" | +* +* @param {Password_Reset_SuccessInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const password_reset_success: ((inputs?: Password_Reset_SuccessInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Password_Reset_SuccessInputs = {}; diff --git a/packages/webui/paraglide/messages/password_reset_success.js b/packages/webui/paraglide/messages/password_reset_success.js new file mode 100644 index 00000000..7b5f3d29 --- /dev/null +++ b/packages/webui/paraglide/messages/password_reset_success.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Password_Reset_SuccessInputs */ + +const en_password_reset_success = /** @type {(inputs: Password_Reset_SuccessInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Password reset successfully!`) +}; + +const zh_password_reset_success = /** @type {(inputs: Password_Reset_SuccessInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`密码重置成功!`) +}; + +/** +* | output | +* | --- | +* | "Password reset successfully!" | +* +* @param {Password_Reset_SuccessInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const password_reset_success = /** @type {((inputs?: Password_Reset_SuccessInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_password_reset_success(inputs) + return zh_password_reset_success(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/password_reset_success_description.d.ts b/packages/webui/paraglide/messages/password_reset_success_description.d.ts new file mode 100644 index 00000000..e919c70e --- /dev/null +++ b/packages/webui/paraglide/messages/password_reset_success_description.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "You will be redirected to the login page shortly." | +* +* @param {Password_Reset_Success_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const password_reset_success_description: ((inputs?: Password_Reset_Success_DescriptionInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Password_Reset_Success_DescriptionInputs = {}; diff --git a/packages/webui/paraglide/messages/password_reset_success_description.js b/packages/webui/paraglide/messages/password_reset_success_description.js new file mode 100644 index 00000000..08c44fd6 --- /dev/null +++ b/packages/webui/paraglide/messages/password_reset_success_description.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Password_Reset_Success_DescriptionInputs */ + +const en_password_reset_success_description = /** @type {(inputs: Password_Reset_Success_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`You will be redirected to the login page shortly.`) +}; + +const zh_password_reset_success_description = /** @type {(inputs: Password_Reset_Success_DescriptionInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`您将很快被重定向到登录页面。`) +}; + +/** +* | output | +* | --- | +* | "You will be redirected to the login page shortly." | +* +* @param {Password_Reset_Success_DescriptionInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const password_reset_success_description = /** @type {((inputs?: Password_Reset_Success_DescriptionInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_password_reset_success_description(inputs) + return zh_password_reset_success_description(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/passwords_do_not_match.d.ts b/packages/webui/paraglide/messages/passwords_do_not_match.d.ts new file mode 100644 index 00000000..2a3a49ac --- /dev/null +++ b/packages/webui/paraglide/messages/passwords_do_not_match.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Passwords do not match" | +* +* @param {Passwords_Do_Not_MatchInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const passwords_do_not_match: ((inputs?: Passwords_Do_Not_MatchInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Passwords_Do_Not_MatchInputs = {}; diff --git a/packages/webui/paraglide/messages/passwords_do_not_match.js b/packages/webui/paraglide/messages/passwords_do_not_match.js new file mode 100644 index 00000000..2ce620d9 --- /dev/null +++ b/packages/webui/paraglide/messages/passwords_do_not_match.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Passwords_Do_Not_MatchInputs */ + +const en_passwords_do_not_match = /** @type {(inputs: Passwords_Do_Not_MatchInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Passwords do not match`) +}; + +const zh_passwords_do_not_match = /** @type {(inputs: Passwords_Do_Not_MatchInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`两次输入的密码不一致`) +}; + +/** +* | output | +* | --- | +* | "Passwords do not match" | +* +* @param {Passwords_Do_Not_MatchInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const passwords_do_not_match = /** @type {((inputs?: Passwords_Do_Not_MatchInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_passwords_do_not_match(inputs) + return zh_passwords_do_not_match(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/reset_password.d.ts b/packages/webui/paraglide/messages/reset_password.d.ts new file mode 100644 index 00000000..e5ddcec7 --- /dev/null +++ b/packages/webui/paraglide/messages/reset_password.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Reset Password" | +* +* @param {Reset_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const reset_password: ((inputs?: Reset_PasswordInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Reset_PasswordInputs = {}; diff --git a/packages/webui/paraglide/messages/reset_password.js b/packages/webui/paraglide/messages/reset_password.js new file mode 100644 index 00000000..f26c6697 --- /dev/null +++ b/packages/webui/paraglide/messages/reset_password.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Reset_PasswordInputs */ + +const en_reset_password = /** @type {(inputs: Reset_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Reset Password`) +}; + +const zh_reset_password = /** @type {(inputs: Reset_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`重置密码`) +}; + +/** +* | output | +* | --- | +* | "Reset Password" | +* +* @param {Reset_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const reset_password = /** @type {((inputs?: Reset_PasswordInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_reset_password(inputs) + return zh_reset_password(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/reset_password_subtitle.d.ts b/packages/webui/paraglide/messages/reset_password_subtitle.d.ts new file mode 100644 index 00000000..18fe2afb --- /dev/null +++ b/packages/webui/paraglide/messages/reset_password_subtitle.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Enter your new password below." | +* +* @param {Reset_Password_SubtitleInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const reset_password_subtitle: ((inputs?: Reset_Password_SubtitleInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Reset_Password_SubtitleInputs = {}; diff --git a/packages/webui/paraglide/messages/reset_password_subtitle.js b/packages/webui/paraglide/messages/reset_password_subtitle.js new file mode 100644 index 00000000..2a904686 --- /dev/null +++ b/packages/webui/paraglide/messages/reset_password_subtitle.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Reset_Password_SubtitleInputs */ + +const en_reset_password_subtitle = /** @type {(inputs: Reset_Password_SubtitleInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Enter your new password below.`) +}; + +const zh_reset_password_subtitle = /** @type {(inputs: Reset_Password_SubtitleInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`请在下方输入您的新密码。`) +}; + +/** +* | output | +* | --- | +* | "Enter your new password below." | +* +* @param {Reset_Password_SubtitleInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const reset_password_subtitle = /** @type {((inputs?: Reset_Password_SubtitleInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_reset_password_subtitle(inputs) + return zh_reset_password_subtitle(inputs) +}); \ No newline at end of file diff --git a/packages/webui/paraglide/messages/resetting_password.d.ts b/packages/webui/paraglide/messages/resetting_password.d.ts new file mode 100644 index 00000000..0377b084 --- /dev/null +++ b/packages/webui/paraglide/messages/resetting_password.d.ts @@ -0,0 +1,16 @@ +/** +* | output | +* | --- | +* | "Resetting password..." | +* +* @param {Resetting_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const resetting_password: ((inputs?: Resetting_PasswordInputs, options?: { + locale?: "en" | "zh"; +}) => LocalizedString) & import("../runtime.js").MessageMetadata; +export type LocalizedString = import("../runtime.js").LocalizedString; +export type Resetting_PasswordInputs = {}; diff --git a/packages/webui/paraglide/messages/resetting_password.js b/packages/webui/paraglide/messages/resetting_password.js new file mode 100644 index 00000000..ea53c0d3 --- /dev/null +++ b/packages/webui/paraglide/messages/resetting_password.js @@ -0,0 +1,29 @@ +/* eslint-disable */ +import { getLocale, experimentalStaticLocale } from '../runtime.js'; + +/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */ + +/** @typedef {{}} Resetting_PasswordInputs */ + +const en_resetting_password = /** @type {(inputs: Resetting_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`Resetting password...`) +}; + +const zh_resetting_password = /** @type {(inputs: Resetting_PasswordInputs) => LocalizedString} */ () => { + return /** @type {LocalizedString} */ (`正在重置密码...`) +}; + +/** +* | output | +* | --- | +* | "Resetting password..." | +* +* @param {Resetting_PasswordInputs} inputs +* @param {{ locale?: "en" | "zh" }} options +* @returns {LocalizedString} +*/ +export const resetting_password = /** @type {((inputs?: Resetting_PasswordInputs, options?: { locale?: "en" | "zh" }) => LocalizedString) & import('../runtime.js').MessageMetadata} */ ((inputs = {}, options = {}) => { + const locale = experimentalStaticLocale ?? options.locale ?? getLocale() + if (locale === "en") return en_resetting_password(inputs) + return zh_resetting_password(inputs) +}); \ No newline at end of file diff --git a/packages/webui/routeTree.gen.ts b/packages/webui/routeTree.gen.ts index e3d36ed0..1ae24c79 100644 --- a/packages/webui/routeTree.gen.ts +++ b/packages/webui/routeTree.gen.ts @@ -10,6 +10,7 @@ import { Route as rootRouteImport } from './routes/__root' import { Route as SignupRouteImport } from './routes/signup' +import { Route as ResetPasswordRouteImport } from './routes/reset-password' import { Route as LoginRouteImport } from './routes/login' import { Route as IndexRouteImport } from './routes/index' import { Route as ShareShareIdRouteImport } from './routes/share/$shareId' @@ -36,6 +37,11 @@ const SignupRoute = SignupRouteImport.update({ path: '/signup', getParentRoute: () => rootRouteImport, } as any) +const ResetPasswordRoute = ResetPasswordRouteImport.update({ + id: '/reset-password', + path: '/reset-password', + getParentRoute: () => rootRouteImport, +} as any).lazy(() => import('./routes/reset-password.lazy').then((d) => d.Route)) const LoginRoute = LoginRouteImport.update({ id: '/login', path: '/login', @@ -154,6 +160,7 @@ const ProjectsProjectIdFoldersFolderIdAgentsmdRoute = export interface FileRoutesByFullPath { '/': typeof IndexRoute '/login': typeof LoginRoute + '/reset-password': typeof ResetPasswordRoute '/signup': typeof SignupRoute '/share/$shareId': typeof ShareShareIdRouteWithChildren '/projects/$projectId/agentsmd': typeof ProjectsProjectIdAgentsmdRoute @@ -177,6 +184,7 @@ export interface FileRoutesByFullPath { export interface FileRoutesByTo { '/': typeof IndexRoute '/login': typeof LoginRoute + '/reset-password': typeof ResetPasswordRoute '/signup': typeof SignupRoute '/projects/$projectId/agentsmd': typeof ProjectsProjectIdAgentsmdRoute '/projects/$projectId/recently-deleted': typeof ProjectsProjectIdRecentlyDeletedRoute @@ -200,6 +208,7 @@ export interface FileRoutesById { __root__: typeof rootRouteImport '/': typeof IndexRoute '/login': typeof LoginRoute + '/reset-password': typeof ResetPasswordRoute '/signup': typeof SignupRoute '/share/$shareId': typeof ShareShareIdRouteWithChildren '/projects/$projectId/agentsmd': typeof ProjectsProjectIdAgentsmdRoute @@ -225,6 +234,7 @@ export interface FileRouteTypes { fullPaths: | '/' | '/login' + | '/reset-password' | '/signup' | '/share/$shareId' | '/projects/$projectId/agentsmd' @@ -248,6 +258,7 @@ export interface FileRouteTypes { to: | '/' | '/login' + | '/reset-password' | '/signup' | '/projects/$projectId/agentsmd' | '/projects/$projectId/recently-deleted' @@ -270,6 +281,7 @@ export interface FileRouteTypes { | '__root__' | '/' | '/login' + | '/reset-password' | '/signup' | '/share/$shareId' | '/projects/$projectId/agentsmd' @@ -294,6 +306,7 @@ export interface FileRouteTypes { export interface RootRouteChildren { IndexRoute: typeof IndexRoute LoginRoute: typeof LoginRoute + ResetPasswordRoute: typeof ResetPasswordRoute SignupRoute: typeof SignupRoute ShareShareIdRoute: typeof ShareShareIdRouteWithChildren ProjectsProjectIdAgentsmdRoute: typeof ProjectsProjectIdAgentsmdRoute @@ -321,6 +334,13 @@ declare module '@tanstack/react-router' { preLoaderRoute: typeof SignupRouteImport parentRoute: typeof rootRouteImport } + '/reset-password': { + id: '/reset-password' + path: '/reset-password' + fullPath: '/reset-password' + preLoaderRoute: typeof ResetPasswordRouteImport + parentRoute: typeof rootRouteImport + } '/login': { id: '/login' path: '/login' @@ -481,6 +501,7 @@ const ShareShareIdRouteWithChildren = ShareShareIdRoute._addFileChildren(ShareSh const rootRouteChildren: RootRouteChildren = { IndexRoute: IndexRoute, LoginRoute: LoginRoute, + ResetPasswordRoute: ResetPasswordRoute, SignupRoute: SignupRoute, ShareShareIdRoute: ShareShareIdRouteWithChildren, ProjectsProjectIdAgentsmdRoute: ProjectsProjectIdAgentsmdRoute, diff --git a/packages/webui/routes/reset-password.lazy.tsx b/packages/webui/routes/reset-password.lazy.tsx new file mode 100644 index 00000000..d8185128 --- /dev/null +++ b/packages/webui/routes/reset-password.lazy.tsx @@ -0,0 +1,212 @@ +import { AuthLayout } from '@/ui/components/auth-layout' +import { Button } from '@/ui/components/ui/button' +import { Input } from '@/ui/components/ui/input' +import { Label } from '@/ui/components/ui/label' +import { resetPassword } from '@/ui/lib/auth-client' +import { m } from '@/ui/paraglide/messages.js' +import { zodResolver } from '@hookform/resolvers/zod' +import { createLazyFileRoute, Link, useNavigate } from '@tanstack/react-router' +import { AlertCircle, ArrowRight, CheckCircle2, KeyRound, Loader2, Lock } from 'lucide-react' +import { useEffect, useState } from 'react' +import { useForm } from 'react-hook-form' +import { z } from 'zod' + +const resetPasswordFormSchema = z + .object({ + password: z.string().min(3, m.password_min_length()), + confirmPassword: z.string().min(3, m.password_min_length()), + }) + .refine((data) => data.password === data.confirmPassword, { + message: m.passwords_do_not_match(), + path: ['confirmPassword'], + }) + +type ResetPasswordFormSchema = z.infer + +export const Route = createLazyFileRoute('/reset-password')({ + component: ResetPasswordPage, +}) + +function ResetPasswordPage() { + const navigate = useNavigate() + const search = Route.useSearch() + const token = search.token || '' + + const [error, setError] = useState(null) + const [loading, setLoading] = useState(false) + const [success, setSuccess] = useState(false) + + const form = useForm({ + resolver: zodResolver(resetPasswordFormSchema), + defaultValues: { + password: '', + confirmPassword: '', + }, + }) + + useEffect(() => { + if (success) { + const timer = setTimeout(() => { + navigate({ to: '/login' }) + }, 3000) + return () => clearTimeout(timer) + } + }, [success, navigate]) + + const onSubmit = async (data: ResetPasswordFormSchema) => { + if (!token) { + setError(m.invalid_reset_token()) + return + } + + setLoading(true) + setError(null) + + const { error: resetError } = await resetPassword({ + newPassword: data.password, + token, + }) + + setLoading(false) + + if (resetError) { + setError(resetError.message || m.invalid_reset_token()) + return + } + + setSuccess(true) + } + + return ( + +
+

{m.reset_password()}

+

{m.reset_password_subtitle()}

+
+ + {!token ? ( +
+
+ +
+

{m.invalid_reset_token()}

+

{m.invalid_reset_token_description()}

+
+
+ + + + +
+ ) : success ? ( +
+
+ +
+

{m.password_reset_success()}

+

+ {m.password_reset_success_description()} +

+
+
+ + + + +
+ ) : ( +
+ {error && ( +
+ {error} +
+ )} + +
+ +
+ + +
+ {form.formState.errors.password && ( +

+ {form.formState.errors.password.message} +

+ )} +
+ +
+ +
+ + +
+ {form.formState.errors.confirmPassword && ( +

+ {form.formState.errors.confirmPassword.message} +

+ )} +
+ + + +
+ + {m.go_to_login()} + +
+
+ )} +
+ ) +} diff --git a/packages/webui/routes/reset-password.tsx b/packages/webui/routes/reset-password.tsx new file mode 100644 index 00000000..4a5b23e3 --- /dev/null +++ b/packages/webui/routes/reset-password.tsx @@ -0,0 +1,18 @@ +import { createFileRoute, redirect } from '@tanstack/react-router' +import { useAuthStore } from '@/ui/stores/auth' +import { z } from 'zod' + +const searchSchema = z.object({ + token: z.string().catch(''), +}) + +export const Route = createFileRoute('/reset-password')({ + validateSearch: (search) => searchSchema.parse(search), + beforeLoad: () => { + if (useAuthStore.getState().user) { + throw redirect({ + to: '/', + }) + } + }, +})