@zhang_libo/resource-hub 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +80 -0
- package/README.ja.md +80 -0
- package/README.md +79 -0
- package/README.zh-TW.md +80 -0
- package/bin/cli.js +10 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +59 -0
- package/dist/app.js.map +1 -0
- package/dist/db/index.js +12 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/migrate.d.ts +3 -0
- package/dist/db/migrate.d.ts.map +1 -0
- package/dist/db/migrate.js +169 -0
- package/dist/db/migrate.js.map +1 -0
- package/dist/db/schema.d.ts +743 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +88 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/i18n.js +309 -0
- package/dist/i18n.js.map +1 -0
- package/dist/plugins/admin.d.ts +4 -0
- package/dist/plugins/admin.d.ts.map +1 -0
- package/dist/plugins/admin.js +19 -0
- package/dist/plugins/admin.js.map +1 -0
- package/dist/plugins/auth.d.ts +4 -0
- package/dist/plugins/auth.d.ts.map +1 -0
- package/dist/plugins/auth.js +35 -0
- package/dist/plugins/auth.js.map +1 -0
- package/dist/routes/auth.d.ts +4 -0
- package/dist/routes/auth.d.ts.map +1 -0
- package/dist/routes/auth.js +352 -0
- package/dist/routes/auth.js.map +1 -0
- package/dist/routes/categories.d.ts +4 -0
- package/dist/routes/categories.d.ts.map +1 -0
- package/dist/routes/categories.js +112 -0
- package/dist/routes/categories.js.map +1 -0
- package/dist/routes/config.d.ts +4 -0
- package/dist/routes/config.d.ts.map +1 -0
- package/dist/routes/config.js +227 -0
- package/dist/routes/config.js.map +1 -0
- package/dist/routes/resources.d.ts +4 -0
- package/dist/routes/resources.d.ts.map +1 -0
- package/dist/routes/resources.js +474 -0
- package/dist/routes/resources.js.map +1 -0
- package/dist/routes/tags.d.ts +4 -0
- package/dist/routes/tags.d.ts.map +1 -0
- package/dist/routes/tags.js +37 -0
- package/dist/routes/tags.js.map +1 -0
- package/dist/routes/users.d.ts +4 -0
- package/dist/routes/users.d.ts.map +1 -0
- package/dist/routes/users.js +181 -0
- package/dist/routes/users.js.map +1 -0
- package/dist/services/crypto.js +49 -0
- package/dist/services/crypto.js.map +1 -0
- package/dist/services/mail.d.ts +16 -0
- package/dist/services/mail.d.ts.map +1 -0
- package/dist/services/mail.js +33 -0
- package/dist/services/mail.js.map +1 -0
- package/dist/services/rsa.js +49 -0
- package/dist/services/rsa.js.map +1 -0
- package/dist/services/token.d.ts +9 -0
- package/dist/services/token.d.ts.map +1 -0
- package/dist/services/token.js +29 -0
- package/dist/services/token.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -0
- package/public/admin/AdminCategories.jsx +310 -0
- package/public/admin/AdminConfig.jsx +254 -0
- package/public/admin/AdminEmail.jsx +279 -0
- package/public/admin/AdminTags.jsx +263 -0
- package/public/admin/AdminUsers.jsx +452 -0
- package/public/app.jsx +186 -0
- package/public/components/ConfirmDialog.jsx +78 -0
- package/public/components/DropdownSelect.jsx +281 -0
- package/public/components/EmailPreviewModal.jsx +104 -0
- package/public/components/EmptyState.jsx +50 -0
- package/public/components/Modal.jsx +127 -0
- package/public/components/PasswordStrength.jsx +45 -0
- package/public/components/Skeleton.jsx +68 -0
- package/public/components/Toast.jsx +80 -0
- package/public/components/TooltipIconButton.jsx +55 -0
- package/public/context/AppContext.jsx +314 -0
- package/public/features/BatchResourceModal.jsx +606 -0
- package/public/features/ChangePasswordModal.jsx +187 -0
- package/public/features/ProfileModal.jsx +170 -0
- package/public/features/ResourceCard.jsx +422 -0
- package/public/features/ResourceFormModal.jsx +915 -0
- package/public/features/ResourceRow.jsx +287 -0
- package/public/features/ResourceTimeline.jsx +472 -0
- package/public/hooks/useApi.jsx +26 -0
- package/public/hooks/useRouter.jsx +35 -0
- package/public/index.html +258 -0
- package/public/layout/AdminLayout.jsx +167 -0
- package/public/layout/AppLayout.jsx +119 -0
- package/public/layout/AuthLayout.jsx +503 -0
- package/public/layout/Header.jsx +543 -0
- package/public/layout/Sidebar.jsx +175 -0
- package/public/pages/AdminPage.jsx +30 -0
- package/public/pages/ForgotPasswordPage.jsx +93 -0
- package/public/pages/HomePage.jsx +2297 -0
- package/public/pages/LoginPage.jsx +191 -0
- package/public/pages/RegisterPage.jsx +137 -0
- package/public/pages/ResetPasswordPage.jsx +169 -0
- package/public/pages/SetupPage.jsx +157 -0
- package/public/utils/helpers.jsx +152 -0
- package/public/utils/i18n.jsx +1374 -0
- package/public/utils/preferences.jsx +220 -0
- package/public/utils/security.jsx +88 -0
- package/public/utils/theme.jsx +24 -0
- package/public/vendor/babel.min.js +2 -0
- package/public/vendor/lucide-react.min.js +9 -0
- package/public/vendor/react-dom.development.js +29869 -0
- package/public/vendor/react.development.js +3342 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
function LoginPage() {
|
|
2
|
+
const state = window.useAppState();
|
|
3
|
+
const dispatch = window.useAppDispatch();
|
|
4
|
+
const { navigate } = window.useRouter();
|
|
5
|
+
const { request } = window.useApi();
|
|
6
|
+
const { AlertCircle, Eye, EyeOff, Loader, ShieldCheck } = lucide;
|
|
7
|
+
|
|
8
|
+
const [form, setForm] = React.useState({ username: '', password: '' });
|
|
9
|
+
const [showPassword, setShowPassword] = React.useState(false);
|
|
10
|
+
const [errors, setErrors] = React.useState({ username: '', password: '', form: '' });
|
|
11
|
+
const [loading, setLoading] = React.useState(false);
|
|
12
|
+
|
|
13
|
+
const config = state?.config || {};
|
|
14
|
+
const siteTitle = config.siteTitle || 'ResourceHub';
|
|
15
|
+
const logoLetter = (siteTitle.trim().charAt(0) || 'R').toUpperCase();
|
|
16
|
+
const authStyles = window.authStyles;
|
|
17
|
+
|
|
18
|
+
const validateField = React.useCallback((field, value) => {
|
|
19
|
+
const normalized = typeof value === 'string' ? value.trim() : value;
|
|
20
|
+
if (field === 'username') return normalized ? '' : '请输入用户名';
|
|
21
|
+
if (field === 'password') return value ? '' : '请输入密码';
|
|
22
|
+
return '';
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
const validateForm = React.useCallback(() => ({
|
|
26
|
+
username: validateField('username', form.username),
|
|
27
|
+
password: validateField('password', form.password),
|
|
28
|
+
}), [form.password, form.username, validateField]);
|
|
29
|
+
|
|
30
|
+
const updateField = (field, value) => {
|
|
31
|
+
setForm((prev) => ({ ...prev, [field]: value }));
|
|
32
|
+
setErrors((prev) => ({
|
|
33
|
+
...prev,
|
|
34
|
+
[field]: prev[field] ? validateField(field, value) : '',
|
|
35
|
+
form: '',
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const handleFieldBlur = (field) => {
|
|
40
|
+
setErrors((prev) => ({
|
|
41
|
+
...prev,
|
|
42
|
+
[field]: validateField(field, form[field]),
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handleSubmit = async (e) => {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
const nextErrors = validateForm();
|
|
49
|
+
if (nextErrors.username || nextErrors.password) {
|
|
50
|
+
setErrors({ ...nextErrors, form: '' });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setLoading(true);
|
|
54
|
+
setErrors((prev) => ({ ...prev, form: '' }));
|
|
55
|
+
try {
|
|
56
|
+
const { passwordEnc, ts } = await window.security.encryptPasswordWithTs(form.password);
|
|
57
|
+
const { ok, data } = await request('/api/auth/login', {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
body: JSON.stringify({ username: form.username, passwordEnc, ts }),
|
|
60
|
+
});
|
|
61
|
+
if (ok) {
|
|
62
|
+
dispatch({ type: 'LOGIN', user: data.data.user, token: data.data.token });
|
|
63
|
+
navigate('#/');
|
|
64
|
+
} else {
|
|
65
|
+
setErrors((prev) => ({ ...prev, form: '用户名或密码错误,请重新输入' }));
|
|
66
|
+
}
|
|
67
|
+
} finally {
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<window.AuthLayout>
|
|
74
|
+
<window.AuthCard
|
|
75
|
+
width="452px"
|
|
76
|
+
kicker="统一访问入口"
|
|
77
|
+
title="登录账号"
|
|
78
|
+
subtitle={config.siteSubtitle || '统一管理与访问你的资源'}
|
|
79
|
+
logoLetter={logoLetter}
|
|
80
|
+
>
|
|
81
|
+
<form onSubmit={handleSubmit}>
|
|
82
|
+
<div style={authStyles.field}>
|
|
83
|
+
<label style={authStyles.label}>用户名</label>
|
|
84
|
+
<input
|
|
85
|
+
className="rh-auth-input"
|
|
86
|
+
type="text"
|
|
87
|
+
value={form.username}
|
|
88
|
+
name="username"
|
|
89
|
+
autoComplete="username"
|
|
90
|
+
autoFocus
|
|
91
|
+
aria-invalid={!!errors.username}
|
|
92
|
+
onChange={(e) => updateField('username', e.target.value)}
|
|
93
|
+
onBlur={() => handleFieldBlur('username')}
|
|
94
|
+
placeholder="请输入用户名"
|
|
95
|
+
disabled={loading}
|
|
96
|
+
style={authStyles.input(!!errors.username)}
|
|
97
|
+
/>
|
|
98
|
+
{errors.username ? <div style={authStyles.errorText}>{errors.username}</div> : null}
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<div style={{ ...authStyles.field, marginBottom: errors.password ? '14px' : '12px' }}>
|
|
102
|
+
<label style={authStyles.label}>密码</label>
|
|
103
|
+
<div style={{ position: 'relative' }}>
|
|
104
|
+
<input
|
|
105
|
+
className="rh-auth-input"
|
|
106
|
+
type={showPassword ? 'text' : 'password'}
|
|
107
|
+
value={form.password}
|
|
108
|
+
name="password"
|
|
109
|
+
autoComplete="current-password"
|
|
110
|
+
aria-invalid={!!errors.password}
|
|
111
|
+
onChange={(e) => updateField('password', e.target.value)}
|
|
112
|
+
onBlur={() => handleFieldBlur('password')}
|
|
113
|
+
placeholder="请输入密码"
|
|
114
|
+
disabled={loading}
|
|
115
|
+
style={authStyles.input(!!errors.password, true)}
|
|
116
|
+
/>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
onClick={() => setShowPassword(v => !v)}
|
|
120
|
+
disabled={loading}
|
|
121
|
+
aria-label={showPassword ? '隐藏密码' : '显示密码'}
|
|
122
|
+
style={{
|
|
123
|
+
...authStyles.passwordToggle,
|
|
124
|
+
color: showPassword ? 'var(--brand-strong)' : authStyles.passwordToggle.color,
|
|
125
|
+
background: showPassword
|
|
126
|
+
? 'color-mix(in srgb, var(--brand-soft) 72%, transparent)'
|
|
127
|
+
: authStyles.passwordToggle.background,
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
{showPassword ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
131
|
+
</button>
|
|
132
|
+
</div>
|
|
133
|
+
{errors.password ? <div style={authStyles.errorText}>{errors.password}</div> : null}
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
{errors.form && (
|
|
137
|
+
<div role="alert" aria-live="polite" style={authStyles.errorBanner}>
|
|
138
|
+
<AlertCircle size={16} style={{ flexShrink: 0 }} />
|
|
139
|
+
<span>{errors.form}</span>
|
|
140
|
+
</div>
|
|
141
|
+
)}
|
|
142
|
+
|
|
143
|
+
<button
|
|
144
|
+
type="submit"
|
|
145
|
+
disabled={loading}
|
|
146
|
+
aria-busy={loading}
|
|
147
|
+
style={{ ...authStyles.primaryButton(loading), marginBottom: '12px' }}
|
|
148
|
+
>
|
|
149
|
+
{loading && <Loader size={16} />}
|
|
150
|
+
{loading ? '登录中...' : '登录'}
|
|
151
|
+
</button>
|
|
152
|
+
|
|
153
|
+
<div
|
|
154
|
+
style={{
|
|
155
|
+
display: 'flex',
|
|
156
|
+
alignItems: 'flex-start',
|
|
157
|
+
gap: '10px',
|
|
158
|
+
padding: '12px 14px',
|
|
159
|
+
borderRadius: '12px',
|
|
160
|
+
background: 'color-mix(in srgb, var(--brand-soft) 54%, var(--surface-elevated))',
|
|
161
|
+
border: '1px solid color-mix(in srgb, var(--brand) 16%, var(--border))',
|
|
162
|
+
color: 'var(--text-secondary)',
|
|
163
|
+
fontSize: '12px',
|
|
164
|
+
lineHeight: 1.6,
|
|
165
|
+
marginBottom: '18px',
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
<ShieldCheck size={16} style={{ flexShrink: 0, marginTop: '1px', color: 'var(--brand-strong)' }} />
|
|
169
|
+
<span>如无法登录或注册,请联系管理员确认账号与注册策略。</span>
|
|
170
|
+
</div>
|
|
171
|
+
|
|
172
|
+
<div style={{ ...authStyles.footerRow, justifyContent: config.enableRegister ? 'space-between' : 'flex-start', gap: '14px', alignItems: 'center' }}>
|
|
173
|
+
<a href="#/forgot-password" className="rh-auth-text-link">
|
|
174
|
+
忘记密码?
|
|
175
|
+
</a>
|
|
176
|
+
{config.enableRegister ? (
|
|
177
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '6px', flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
|
178
|
+
<span style={{ fontSize: '13px', color: 'var(--text-secondary)' }}>没有账号?</span>
|
|
179
|
+
<a href="#/register" className="rh-auth-text-link rh-auth-text-link--strong">
|
|
180
|
+
注册账号
|
|
181
|
+
</a>
|
|
182
|
+
</div>
|
|
183
|
+
) : null}
|
|
184
|
+
</div>
|
|
185
|
+
</form>
|
|
186
|
+
</window.AuthCard>
|
|
187
|
+
</window.AuthLayout>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
window.LoginPage = LoginPage;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
function RegisterPage() {
|
|
2
|
+
const state = window.useAppState();
|
|
3
|
+
const dispatch = window.useAppDispatch();
|
|
4
|
+
const { navigate } = window.useRouter();
|
|
5
|
+
const { request } = window.useApi();
|
|
6
|
+
const { Loader } = lucide;
|
|
7
|
+
|
|
8
|
+
const [form, setForm] = React.useState({ username: '', displayName: '', email: '' });
|
|
9
|
+
const [errors, setErrors] = React.useState({});
|
|
10
|
+
const [loading, setLoading] = React.useState(false);
|
|
11
|
+
|
|
12
|
+
const config = state?.config;
|
|
13
|
+
|
|
14
|
+
const validate = () => {
|
|
15
|
+
const errs = {};
|
|
16
|
+
if (!/^[a-zA-Z0-9_]{3,20}$/.test(form.username) || /^\d+$/.test(form.username))
|
|
17
|
+
errs.username = '用户名3-20位,仅字母数字下划线,不能纯数字';
|
|
18
|
+
if (!form.displayName || form.displayName.length > 30)
|
|
19
|
+
errs.displayName = '显示名称不能为空(最多30字符)';
|
|
20
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email))
|
|
21
|
+
errs.email = '请输入有效的邮箱地址';
|
|
22
|
+
return errs;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handleSubmit = async (e) => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
const errs = validate();
|
|
28
|
+
if (Object.keys(errs).length > 0) { setErrors(errs); return; }
|
|
29
|
+
setLoading(true);
|
|
30
|
+
try {
|
|
31
|
+
const { ok, data } = await request('/api/auth/register', {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
body: JSON.stringify({ username: form.username, displayName: form.displayName, email: form.email }),
|
|
34
|
+
});
|
|
35
|
+
if (ok) {
|
|
36
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'success', message: '注册成功!初始密码已发送至邮箱' });
|
|
37
|
+
if (data.emailPreview) dispatch({ type: 'SET_EMAIL_PREVIEW', emailPreview: data.emailPreview });
|
|
38
|
+
setTimeout(() => navigate('#/login'), 3000);
|
|
39
|
+
} else {
|
|
40
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'error', message: data.error || '注册失败' });
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
setLoading(false);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const inputStyle = (field) => ({
|
|
48
|
+
width: '100%', padding: '9px 12px',
|
|
49
|
+
border: `1px solid ${errors[field] ? 'var(--danger)' : 'var(--border)'}`,
|
|
50
|
+
borderRadius: '8px', background: 'var(--bg-secondary)',
|
|
51
|
+
color: 'var(--text-primary)', fontSize: '14px',
|
|
52
|
+
outline: 'none', boxSizing: 'border-box',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (config && config.enableRegister === false) {
|
|
56
|
+
return (
|
|
57
|
+
<window.AuthLayout>
|
|
58
|
+
<div style={{ width: '400px', maxWidth: '100%' }}>
|
|
59
|
+
<div style={{
|
|
60
|
+
background: 'color-mix(in srgb, var(--surface-elevated) 94%, var(--surface-muted))', border: '1px solid color-mix(in srgb, var(--outline-strong) 84%, var(--border))',
|
|
61
|
+
borderRadius: '24px', padding: '36px', textAlign: 'center',
|
|
62
|
+
boxShadow: 'var(--shadow-modal)',
|
|
63
|
+
}}>
|
|
64
|
+
<p style={{ fontSize: '15px', color: 'var(--text-secondary)', marginBottom: '20px' }}>注册功能暂未开放</p>
|
|
65
|
+
<button onClick={() => navigate('#/login')} style={{
|
|
66
|
+
padding: '9px 24px', background: 'var(--brand)', color: '#fff',
|
|
67
|
+
border: 'none', borderRadius: '8px', cursor: 'pointer', fontSize: '14px',
|
|
68
|
+
}}>去登录</button>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
</window.AuthLayout>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<window.AuthLayout>
|
|
77
|
+
<div style={{ width: '400px', maxWidth: '100%' }}>
|
|
78
|
+
<div style={{
|
|
79
|
+
background: 'color-mix(in srgb, var(--surface-elevated) 94%, var(--surface-muted))', border: '1px solid color-mix(in srgb, var(--outline-strong) 84%, var(--border))',
|
|
80
|
+
borderRadius: '24px', padding: '36px', boxShadow: 'var(--shadow-modal)',
|
|
81
|
+
}}>
|
|
82
|
+
<div style={{ textAlign: 'center', marginBottom: '28px' }}>
|
|
83
|
+
<div style={{ fontSize: '11px', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--brand)', marginBottom: '10px' }}>
|
|
84
|
+
邀请与注册
|
|
85
|
+
</div>
|
|
86
|
+
<div style={{
|
|
87
|
+
width: '48px', height: '48px', borderRadius: '12px',
|
|
88
|
+
background: 'var(--brand)', color: '#fff',
|
|
89
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
90
|
+
fontSize: '20px', fontWeight: 700, margin: '0 auto 16px',
|
|
91
|
+
}}>R</div>
|
|
92
|
+
<h1 style={{ fontSize: '20px', fontWeight: 700, color: 'var(--text-primary)', margin: 0 }}>注册账号</h1>
|
|
93
|
+
</div>
|
|
94
|
+
<form onSubmit={handleSubmit}>
|
|
95
|
+
{[
|
|
96
|
+
{ key: 'username', label: '用户名', type: 'text', placeholder: '仅字母数字下划线,3-20位', autoComplete: 'username' },
|
|
97
|
+
{ key: 'displayName', label: '显示名称', type: 'text', placeholder: '显示给其他用户的名称', autoComplete: 'name' },
|
|
98
|
+
{ key: 'email', label: '邮箱', type: 'email', placeholder: 'your@example.com', autoComplete: 'email' },
|
|
99
|
+
].map(({ key, label, type, placeholder, autoComplete }) => (
|
|
100
|
+
<div key={key} style={{ marginBottom: '14px' }}>
|
|
101
|
+
<label style={{ fontSize: '13px', fontWeight: 500, color: 'var(--text-primary)', display: 'block', marginBottom: '6px' }}>{label}</label>
|
|
102
|
+
<input
|
|
103
|
+
className="rh-auth-input"
|
|
104
|
+
type={type} name={key} value={form[key]} placeholder={placeholder}
|
|
105
|
+
autoComplete={autoComplete}
|
|
106
|
+
onChange={(e) => setForm(f => ({ ...f, [key]: e.target.value }))}
|
|
107
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, [key]: errs[key] })); }}
|
|
108
|
+
style={inputStyle(key)} disabled={loading}
|
|
109
|
+
/>
|
|
110
|
+
{errors[key] && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors[key]}</div>}
|
|
111
|
+
</div>
|
|
112
|
+
))}
|
|
113
|
+
<button type="submit" disabled={loading} style={{
|
|
114
|
+
width: '100%', padding: '10px',
|
|
115
|
+
background: 'var(--brand)', color: '#fff', border: 'none',
|
|
116
|
+
borderRadius: '8px', cursor: loading ? 'not-allowed' : 'pointer',
|
|
117
|
+
fontSize: '14px', fontWeight: 600, marginTop: '8px', marginBottom: '16px',
|
|
118
|
+
opacity: loading ? 0.8 : 1,
|
|
119
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px',
|
|
120
|
+
}}>
|
|
121
|
+
{loading && <Loader size={15} />}
|
|
122
|
+
注册
|
|
123
|
+
</button>
|
|
124
|
+
<div style={{ textAlign: 'center' }}>
|
|
125
|
+
<button type="button" onClick={() => navigate('#/login')}
|
|
126
|
+
style={{ background: 'none', border: 'none', color: 'var(--text-secondary)', cursor: 'pointer', fontSize: '13px' }}>
|
|
127
|
+
已有账号?<span style={{ color: 'var(--brand)' }}>去登录</span>
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
</form>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</window.AuthLayout>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
window.RegisterPage = RegisterPage;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
function ResetPasswordPage() {
|
|
2
|
+
const dispatch = window.useAppDispatch();
|
|
3
|
+
const { route, navigate } = window.useRouter();
|
|
4
|
+
const { request } = window.useApi();
|
|
5
|
+
const { Loader, Eye, EyeOff } = lucide;
|
|
6
|
+
|
|
7
|
+
const token = route.params.token || '';
|
|
8
|
+
const [form, setForm] = React.useState({ password: '', confirmPassword: '' });
|
|
9
|
+
const [resetIdentifier] = React.useState(() => window.sessionStorage?.getItem('rh_reset_identifier') || '');
|
|
10
|
+
const [errors, setErrors] = React.useState({});
|
|
11
|
+
const [loading, setLoading] = React.useState(false);
|
|
12
|
+
const [tokenInvalid, setTokenInvalid] = React.useState(false);
|
|
13
|
+
const [showPw, setShowPw] = React.useState(false);
|
|
14
|
+
const [showCPw, setShowCPw] = React.useState(false);
|
|
15
|
+
|
|
16
|
+
const validate = () => {
|
|
17
|
+
const errs = {};
|
|
18
|
+
if (form.password.length < 8 || !/[a-zA-Z]/.test(form.password) || !/[0-9]/.test(form.password))
|
|
19
|
+
errs.password = '密码至少8位,需包含字母和数字';
|
|
20
|
+
if (form.password !== form.confirmPassword)
|
|
21
|
+
errs.confirmPassword = '两次密码不一致';
|
|
22
|
+
return errs;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handleSubmit = async (e) => {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
const errs = validate();
|
|
28
|
+
if (Object.keys(errs).length > 0) { setErrors(errs); return; }
|
|
29
|
+
setLoading(true);
|
|
30
|
+
try {
|
|
31
|
+
const { ok, data } = await request('/api/auth/reset-password', {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
body: JSON.stringify({
|
|
34
|
+
token,
|
|
35
|
+
newPassword: form.password,
|
|
36
|
+
confirmPassword: form.confirmPassword,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
if (ok) {
|
|
40
|
+
window.sessionStorage?.removeItem('rh_reset_identifier');
|
|
41
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'success', message: '密码已重置,请登录' });
|
|
42
|
+
navigate('#/login');
|
|
43
|
+
} else {
|
|
44
|
+
if (['RESET_TOKEN_INVALID', 'RESET_TOKEN_EXPIRED', 'RESET_TOKEN_USED'].includes(data.code)) {
|
|
45
|
+
setTokenInvalid(true);
|
|
46
|
+
} else if (data.code === 'VALIDATION_ERROR' && data.fields) {
|
|
47
|
+
setErrors(data.fields);
|
|
48
|
+
}
|
|
49
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'error', message: data.error || '重置失败' });
|
|
50
|
+
}
|
|
51
|
+
} finally {
|
|
52
|
+
setLoading(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const inputStyle = (field) => ({
|
|
57
|
+
width: '100%', padding: '9px 40px 9px 12px',
|
|
58
|
+
border: `1px solid ${errors[field] ? 'var(--danger)' : 'var(--border)'}`,
|
|
59
|
+
borderRadius: '8px', background: 'var(--bg-primary)',
|
|
60
|
+
color: 'var(--text-primary)', fontSize: '14px',
|
|
61
|
+
outline: 'none', boxSizing: 'border-box',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!token || tokenInvalid) {
|
|
65
|
+
return (
|
|
66
|
+
<window.AuthLayout>
|
|
67
|
+
<div style={{ width: '400px', maxWidth: '100%' }}>
|
|
68
|
+
<div style={{
|
|
69
|
+
background: 'color-mix(in srgb, var(--surface-elevated) 94%, var(--surface-muted))', border: '1px solid color-mix(in srgb, var(--outline-strong) 84%, var(--border))',
|
|
70
|
+
borderRadius: '24px', padding: '36px', textAlign: 'center',
|
|
71
|
+
boxShadow: 'var(--shadow-modal)',
|
|
72
|
+
}}>
|
|
73
|
+
<p style={{ fontSize: '15px', color: 'var(--danger)', marginBottom: '8px', fontWeight: 500 }}>链接已失效或过期</p>
|
|
74
|
+
<p style={{ fontSize: '14px', color: 'var(--text-secondary)', marginBottom: '20px' }}>请重新发送密码重置链接</p>
|
|
75
|
+
<button onClick={() => navigate('#/forgot-password')} style={{
|
|
76
|
+
padding: '9px 24px', background: 'var(--brand)', color: '#fff',
|
|
77
|
+
border: 'none', borderRadius: '8px', cursor: 'pointer', fontSize: '14px',
|
|
78
|
+
}}>重新发送重置链接</button>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</window.AuthLayout>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<window.AuthLayout>
|
|
87
|
+
<div style={{ width: '400px', maxWidth: '100%' }}>
|
|
88
|
+
<div style={{
|
|
89
|
+
background: 'color-mix(in srgb, var(--surface-elevated) 94%, var(--surface-muted))', border: '1px solid color-mix(in srgb, var(--outline-strong) 84%, var(--border))',
|
|
90
|
+
borderRadius: '24px', padding: '36px', boxShadow: 'var(--shadow-modal)',
|
|
91
|
+
}}>
|
|
92
|
+
<div style={{ fontSize: '11px', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--brand)', marginBottom: '10px' }}>
|
|
93
|
+
重置密码
|
|
94
|
+
</div>
|
|
95
|
+
<h1 style={{ fontSize: '20px', fontWeight: 700, color: 'var(--text-primary)', margin: '0 0 24px' }}>设置新密码</h1>
|
|
96
|
+
<form onSubmit={handleSubmit}>
|
|
97
|
+
<input
|
|
98
|
+
type="text"
|
|
99
|
+
name="username"
|
|
100
|
+
autoComplete="username"
|
|
101
|
+
value={resetIdentifier}
|
|
102
|
+
readOnly
|
|
103
|
+
tabIndex={-1}
|
|
104
|
+
style={{
|
|
105
|
+
position: 'absolute',
|
|
106
|
+
opacity: 0,
|
|
107
|
+
pointerEvents: 'none',
|
|
108
|
+
width: '1px',
|
|
109
|
+
height: '1px',
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
<div style={{ marginBottom: '14px' }}>
|
|
113
|
+
<label style={{ fontSize: '13px', fontWeight: 500, color: 'var(--text-primary)', display: 'block', marginBottom: '6px' }}>新密码</label>
|
|
114
|
+
<div style={{ position: 'relative' }}>
|
|
115
|
+
<input
|
|
116
|
+
className="rh-auth-input"
|
|
117
|
+
type={showPw ? 'text' : 'password'} name="new-password" value={form.password}
|
|
118
|
+
autoComplete="new-password"
|
|
119
|
+
placeholder="至少8位,含字母和数字"
|
|
120
|
+
onChange={(e) => setForm(f => ({ ...f, password: e.target.value }))}
|
|
121
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, password: errs.password })); }}
|
|
122
|
+
style={inputStyle('password')} disabled={loading}
|
|
123
|
+
/>
|
|
124
|
+
<button type="button" onClick={() => setShowPw(v => !v)}
|
|
125
|
+
style={{ position: 'absolute', right: '10px', top: '50%', transform: 'translateY(-50%)', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)' }}>
|
|
126
|
+
{showPw ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
127
|
+
</button>
|
|
128
|
+
</div>
|
|
129
|
+
<window.PasswordStrength password={form.password} />
|
|
130
|
+
{errors.password && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors.password}</div>}
|
|
131
|
+
</div>
|
|
132
|
+
<div style={{ marginBottom: '24px' }}>
|
|
133
|
+
<label style={{ fontSize: '13px', fontWeight: 500, color: 'var(--text-primary)', display: 'block', marginBottom: '6px' }}>确认新密码</label>
|
|
134
|
+
<div style={{ position: 'relative' }}>
|
|
135
|
+
<input
|
|
136
|
+
className="rh-auth-input"
|
|
137
|
+
type={showCPw ? 'text' : 'password'} name="confirm-password" value={form.confirmPassword}
|
|
138
|
+
autoComplete="new-password"
|
|
139
|
+
placeholder="再次输入新密码"
|
|
140
|
+
onChange={(e) => setForm(f => ({ ...f, confirmPassword: e.target.value }))}
|
|
141
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, confirmPassword: errs.confirmPassword })); }}
|
|
142
|
+
style={inputStyle('confirmPassword')} disabled={loading}
|
|
143
|
+
/>
|
|
144
|
+
<button type="button" onClick={() => setShowCPw(v => !v)}
|
|
145
|
+
style={{ position: 'absolute', right: '10px', top: '50%', transform: 'translateY(-50%)', background: 'none', border: 'none', cursor: 'pointer', color: 'var(--text-secondary)' }}>
|
|
146
|
+
{showCPw ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
147
|
+
</button>
|
|
148
|
+
</div>
|
|
149
|
+
{errors.confirmPassword && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors.confirmPassword}</div>}
|
|
150
|
+
</div>
|
|
151
|
+
<button type="submit" disabled={loading} style={{
|
|
152
|
+
width: '100%', padding: '10px',
|
|
153
|
+
background: 'var(--brand)', color: '#fff', border: 'none',
|
|
154
|
+
borderRadius: '8px', cursor: loading ? 'not-allowed' : 'pointer',
|
|
155
|
+
fontSize: '14px', fontWeight: 600,
|
|
156
|
+
opacity: loading ? 0.8 : 1,
|
|
157
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px',
|
|
158
|
+
}}>
|
|
159
|
+
{loading && <Loader size={15} />}
|
|
160
|
+
重置密码
|
|
161
|
+
</button>
|
|
162
|
+
</form>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
</window.AuthLayout>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
window.ResetPasswordPage = ResetPasswordPage;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
function SetupPage() {
|
|
2
|
+
const dispatch = window.useAppDispatch();
|
|
3
|
+
const { navigate } = window.useRouter();
|
|
4
|
+
const { request } = window.useApi();
|
|
5
|
+
const { Loader } = lucide;
|
|
6
|
+
|
|
7
|
+
const [form, setForm] = React.useState({ username: '', displayName: '', email: '', password: '', confirmPassword: '' });
|
|
8
|
+
const [errors, setErrors] = React.useState({});
|
|
9
|
+
const [loading, setLoading] = React.useState(false);
|
|
10
|
+
|
|
11
|
+
const validate = () => {
|
|
12
|
+
const errs = {};
|
|
13
|
+
if (!/^[a-zA-Z0-9_]{3,20}$/.test(form.username) || /^\d+$/.test(form.username))
|
|
14
|
+
errs.username = '用户名3-20位,仅字母数字下划线,不能纯数字';
|
|
15
|
+
if (!form.displayName || form.displayName.length > 30)
|
|
16
|
+
errs.displayName = '显示名称不能为空(最多30字符)';
|
|
17
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email))
|
|
18
|
+
errs.email = '请输入有效的邮箱地址';
|
|
19
|
+
if (form.password.length < 8 || !/[a-zA-Z]/.test(form.password) || !/[0-9]/.test(form.password))
|
|
20
|
+
errs.password = '密码至少8位,需包含字母和数字';
|
|
21
|
+
if (form.password !== form.confirmPassword)
|
|
22
|
+
errs.confirmPassword = '两次密码不一致';
|
|
23
|
+
return errs;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const handleSubmit = async (e) => {
|
|
27
|
+
e.preventDefault();
|
|
28
|
+
const errs = validate();
|
|
29
|
+
if (Object.keys(errs).length > 0) { setErrors(errs); return; }
|
|
30
|
+
setLoading(true);
|
|
31
|
+
try {
|
|
32
|
+
const { ok, data } = await request('/api/auth/setup', {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
body: JSON.stringify({
|
|
35
|
+
username: form.username,
|
|
36
|
+
displayName: form.displayName,
|
|
37
|
+
email: form.email,
|
|
38
|
+
password: form.password,
|
|
39
|
+
confirmPassword: form.confirmPassword,
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
if (ok) {
|
|
43
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'success', message: '初始化成功!请登录' });
|
|
44
|
+
window.location.hash = '#/login';
|
|
45
|
+
window.location.reload();
|
|
46
|
+
} else {
|
|
47
|
+
if (data.code === 'VALIDATION_ERROR' && data.fields) {
|
|
48
|
+
setErrors(data.fields);
|
|
49
|
+
}
|
|
50
|
+
dispatch({ type: 'ADD_TOAST', toastType: 'error', message: data.error || '初始化失败' });
|
|
51
|
+
}
|
|
52
|
+
} finally {
|
|
53
|
+
setLoading(false);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const inputStyle = (field) => ({
|
|
58
|
+
width: '100%', padding: '9px 12px',
|
|
59
|
+
border: `1px solid ${errors[field] ? 'var(--danger)' : 'var(--border)'}`,
|
|
60
|
+
borderRadius: '8px', background: 'var(--bg-secondary)',
|
|
61
|
+
color: 'var(--text-primary)', fontSize: '14px',
|
|
62
|
+
outline: 'none', boxSizing: 'border-box',
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const labelStyle = { fontSize: '13px', fontWeight: 500, color: 'var(--text-primary)', display: 'block', marginBottom: '6px' };
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<window.AuthLayout>
|
|
69
|
+
<div style={{ width: '480px', maxWidth: '100%' }}>
|
|
70
|
+
<div style={{
|
|
71
|
+
background: 'color-mix(in srgb, var(--surface-elevated) 94%, var(--surface-muted))',
|
|
72
|
+
border: '1px solid color-mix(in srgb, var(--outline-strong) 84%, var(--border))',
|
|
73
|
+
borderRadius: '24px',
|
|
74
|
+
padding: '36px',
|
|
75
|
+
boxShadow: 'var(--shadow-modal)',
|
|
76
|
+
}}>
|
|
77
|
+
<div style={{ textAlign: 'center', marginBottom: '32px' }}>
|
|
78
|
+
<div style={{ fontSize: '11px', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--brand)', marginBottom: '10px' }}>
|
|
79
|
+
首次初始化
|
|
80
|
+
</div>
|
|
81
|
+
<div style={{
|
|
82
|
+
width: '56px', height: '56px', borderRadius: '14px',
|
|
83
|
+
background: 'var(--brand)', color: '#fff',
|
|
84
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
85
|
+
fontSize: '24px', fontWeight: 700,
|
|
86
|
+
margin: '0 auto 16px',
|
|
87
|
+
}}>R</div>
|
|
88
|
+
<h1 style={{ fontSize: '20px', fontWeight: 700, color: 'var(--text-primary)', margin: '0 0 8px' }}>
|
|
89
|
+
欢迎使用资源导航系统
|
|
90
|
+
</h1>
|
|
91
|
+
<p style={{ fontSize: '14px', color: 'var(--text-secondary)', margin: 0 }}>
|
|
92
|
+
请先完成初始化,创建管理员账号
|
|
93
|
+
</p>
|
|
94
|
+
</div>
|
|
95
|
+
<form onSubmit={handleSubmit}>
|
|
96
|
+
{[
|
|
97
|
+
{ key: 'username', label: '管理员用户名', type: 'text', placeholder: '仅字母数字下划线,3-20位', autoComplete: 'username' },
|
|
98
|
+
{ key: 'displayName', label: '管理员显示名称', type: 'text', placeholder: '显示给其他用户的名称', autoComplete: 'name' },
|
|
99
|
+
{ key: 'email', label: '管理员邮箱', type: 'email', placeholder: 'admin@example.com', autoComplete: 'email' },
|
|
100
|
+
].map(({ key, label, type, placeholder, autoComplete }) => (
|
|
101
|
+
<div key={key} style={{ marginBottom: '16px' }}>
|
|
102
|
+
<label style={labelStyle}>{label}</label>
|
|
103
|
+
<input
|
|
104
|
+
className="rh-auth-input"
|
|
105
|
+
type={type} name={key} value={form[key]} placeholder={placeholder}
|
|
106
|
+
autoComplete={autoComplete}
|
|
107
|
+
onChange={(e) => setForm(f => ({ ...f, [key]: e.target.value }))}
|
|
108
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, [key]: errs[key] })); }}
|
|
109
|
+
style={inputStyle(key)} disabled={loading}
|
|
110
|
+
/>
|
|
111
|
+
{errors[key] && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors[key]}</div>}
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
<div style={{ marginBottom: '16px' }}>
|
|
115
|
+
<label style={labelStyle}>管理员密码</label>
|
|
116
|
+
<input
|
|
117
|
+
className="rh-auth-input"
|
|
118
|
+
type="password" name="new-password" value={form.password} placeholder="至少8位,含字母和数字"
|
|
119
|
+
autoComplete="new-password"
|
|
120
|
+
onChange={(e) => setForm(f => ({ ...f, password: e.target.value }))}
|
|
121
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, password: errs.password })); }}
|
|
122
|
+
style={inputStyle('password')} disabled={loading}
|
|
123
|
+
/>
|
|
124
|
+
<window.PasswordStrength password={form.password} />
|
|
125
|
+
{errors.password && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors.password}</div>}
|
|
126
|
+
</div>
|
|
127
|
+
<div style={{ marginBottom: '24px' }}>
|
|
128
|
+
<label style={labelStyle}>确认密码</label>
|
|
129
|
+
<input
|
|
130
|
+
className="rh-auth-input"
|
|
131
|
+
type="password" name="confirm-password" value={form.confirmPassword} placeholder="再次输入密码"
|
|
132
|
+
autoComplete="new-password"
|
|
133
|
+
onChange={(e) => setForm(f => ({ ...f, confirmPassword: e.target.value }))}
|
|
134
|
+
onBlur={() => { const errs = validate(); setErrors(prev => ({ ...prev, confirmPassword: errs.confirmPassword })); }}
|
|
135
|
+
style={inputStyle('confirmPassword')} disabled={loading}
|
|
136
|
+
/>
|
|
137
|
+
{errors.confirmPassword && <div style={{ fontSize: '12px', color: 'var(--danger)', marginTop: '4px' }}>{errors.confirmPassword}</div>}
|
|
138
|
+
</div>
|
|
139
|
+
<button type="submit" disabled={loading} style={{
|
|
140
|
+
width: '100%', padding: '10px',
|
|
141
|
+
background: 'var(--brand)', color: '#fff', border: 'none',
|
|
142
|
+
borderRadius: '8px', cursor: loading ? 'not-allowed' : 'pointer',
|
|
143
|
+
fontSize: '14px', fontWeight: 600,
|
|
144
|
+
opacity: loading ? 0.8 : 1,
|
|
145
|
+
display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '8px',
|
|
146
|
+
}}>
|
|
147
|
+
{loading && <Loader size={15} />}
|
|
148
|
+
完成初始化
|
|
149
|
+
</button>
|
|
150
|
+
</form>
|
|
151
|
+
</div>
|
|
152
|
+
</div>
|
|
153
|
+
</window.AuthLayout>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
window.SetupPage = SetupPage;
|