feat(auth): 添加用户注册开关功能
- 在系统设置中新增 allowRegister 配置项控制用户注册 - 实现注册接口的开关检查机制 - 登录页面根据注册开关动态显示或隐藏注册选项 - 首次 Linux.do 登录创建用户时也受注册开关限制 - 更新系统配置文档说明新的认证配置项
This commit is contained in:
@@ -36,7 +36,7 @@ const emptySettings: AdminSettings = {
|
||||
systemPrompt: "",
|
||||
allowCustomChannel: true,
|
||||
},
|
||||
auth: { linuxDo: { enabled: false } },
|
||||
auth: { allowRegister: true, linuxDo: { enabled: false } },
|
||||
},
|
||||
private: { channels: [], promptSync: { enabled: true, cron: "*/5 * * * *" }, auth: { linuxDo: { clientId: "", clientSecret: "" } } },
|
||||
};
|
||||
@@ -371,6 +371,11 @@ export default function AdminSettingsPage() {
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Form.Item name={["public", "auth", "allowRegister"]} label="是否允许用户注册" extra="关闭后隐藏注册入口,注册接口也会拒绝新用户创建" valuePropName="checked">
|
||||
<Switch />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Typography.Title level={5}>模型算力点</Typography.Title>
|
||||
<Table
|
||||
@@ -689,6 +694,7 @@ function normalizePublicSetting(setting: Partial<AdminSettings["public"]> = {}):
|
||||
modelCosts: normalizeModelCosts(setting.modelChannel?.modelCosts || []),
|
||||
},
|
||||
auth: {
|
||||
allowRegister: setting.auth?.allowRegister !== false,
|
||||
linuxDo: {
|
||||
enabled: setting.auth?.linuxDo?.enabled === true,
|
||||
},
|
||||
|
||||
@@ -32,6 +32,7 @@ function LoginContent() {
|
||||
const setSession = useUserStore((state) => state.setSession);
|
||||
const isLoading = useUserStore((state) => state.isLoading);
|
||||
const linuxDoEnabled = useConfigStore((state) => state.publicSettings?.auth?.linuxDo?.enabled === true);
|
||||
const allowRegister = useConfigStore((state) => state.publicSettings?.auth?.allowRegister !== false);
|
||||
const [mode, setMode] = useState<"login" | "register">("login");
|
||||
const redirect = searchParams.get("redirect") || "/";
|
||||
|
||||
@@ -48,8 +49,16 @@ function LoginContent() {
|
||||
});
|
||||
}, [message, redirect, router, searchParams, setSession]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!allowRegister && mode === "register") setMode("login");
|
||||
}, [allowRegister, mode]);
|
||||
|
||||
const submit = async (values: LoginFormValues) => {
|
||||
try {
|
||||
if (mode === "register" && !allowRegister) {
|
||||
message.error("当前未开放注册");
|
||||
return;
|
||||
}
|
||||
if (mode === "register" && values.password !== values.confirmPassword) {
|
||||
message.error("两次输入的密码不一致");
|
||||
return;
|
||||
@@ -87,10 +96,7 @@ function LoginContent() {
|
||||
block
|
||||
value={mode}
|
||||
onChange={(value) => setMode(value as "login" | "register")}
|
||||
options={[
|
||||
{ label: "登录", value: "login" },
|
||||
{ label: "注册", value: "register" },
|
||||
]}
|
||||
options={allowRegister ? [{ label: "登录", value: "login" }, { label: "注册", value: "register" }] : [{ label: "登录", value: "login" }]}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="username" label={<span className="font-medium text-stone-800 dark:text-stone-200">用户名</span>} rules={[{ required: true, message: "请输入用户名" }]}>
|
||||
@@ -104,7 +110,7 @@ function LoginContent() {
|
||||
<Input.Password prefix={<LockOutlined />} autoComplete="new-password" />
|
||||
</Form.Item>
|
||||
) : null}
|
||||
<Space direction="vertical" size={12} style={{ width: "100%" }}>
|
||||
<Space orientation="vertical" size={12} style={{ width: "100%" }}>
|
||||
<Button block type="primary" htmlType="submit" loading={isLoading}>
|
||||
{mode === "register" ? "注册" : "登录"}
|
||||
</Button>
|
||||
|
||||
@@ -186,6 +186,7 @@ export type AdminModelCost = {
|
||||
export type AdminPublicSettings = {
|
||||
modelChannel: AdminPublicModelChannelSettings;
|
||||
auth: {
|
||||
allowRegister: boolean;
|
||||
linuxDo: {
|
||||
enabled: boolean;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user