瀏覽代碼

Feat: Add user registration toggle feature (#6327)

### What problem does this PR solve?

Feat: Add user registration toggle feature. Added a user registration
toggle REGISTER_ENABLED in the settings and .env config file. The user
creation interface now checks the state of this toggle to control the
enabling and disabling of the user registration feature.

the front-end implementation is done, the registration button does not
appear if registration is not allowed. I did the actual tests on my
local server and it worked smoothly.
### Type of change

- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: wenju.li <wenju.li@deepctr.cn>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
tags/v0.18.0
liwenju0 7 月之前
父節點
當前提交
1bb990719e
No account linked to committer's email address

+ 22
- 1
api/apps/system_app.py 查看文件

@@ -37,7 +37,6 @@ from timeit import default_timer as timer

from rag.utils.redis_conn import REDIS_CONN


@manager.route("/version", methods=["GET"]) # noqa: F821
@login_required
def version():
@@ -298,3 +297,25 @@ def rm(token):
[APIToken.tenant_id == current_user.id, APIToken.token == token]
)
return get_json_result(data=True)


@manager.route('/config', methods=['GET']) # noqa: F821
def get_config():
"""
Get system configuration.
---
tags:
- System
responses:
200:
description: Return system configuration
schema:
type: object
properties:
registerEnable:
type: integer 0 means disabled, 1 means enabled
description: Whether user registration is enabled
"""
return get_json_result(data={
"registerEnabled": settings.REGISTER_ENABLED
})

+ 8
- 0
api/apps/user_app.py 查看文件

@@ -562,6 +562,14 @@ def user_add():
schema:
type: object
"""

if not settings.REGISTER_ENABLED:
return get_json_result(
data=False,
message="User registration is disabled!",
code=settings.RetCode.OPERATING_ERROR,
)

req = request.json
email_address = req["email"]


+ 8
- 1
api/settings.py 查看文件

@@ -62,9 +62,12 @@ docStoreConn = None
retrievaler = None
kg_retrievaler = None

# user registration switch
REGISTER_ENABLED = 1


def init_settings():
global LLM, LLM_FACTORY, LLM_BASE_URL, LIGHTEN, DATABASE_TYPE, DATABASE, FACTORY_LLM_INFOS
global LLM, LLM_FACTORY, LLM_BASE_URL, LIGHTEN, DATABASE_TYPE, DATABASE, FACTORY_LLM_INFOS, REGISTER_ENABLED
LIGHTEN = int(os.environ.get('LIGHTEN', "0"))
DATABASE_TYPE = os.getenv("DB_TYPE", 'mysql')
DATABASE = decrypt_database_config(name=DATABASE_TYPE)
@@ -72,6 +75,10 @@ def init_settings():
LLM_DEFAULT_MODELS = LLM.get("default_models", {})
LLM_FACTORY = LLM.get("factory", "Tongyi-Qianwen")
LLM_BASE_URL = LLM.get("base_url")
try:
REGISTER_ENABLED = int(os.environ.get("REGISTER_ENABLED", "1"))
except Exception:
pass
try:
with open(os.path.join(get_project_base_directory(), "conf", "llm_factories.json"), "r") as f:

+ 3
- 0
docker/.env 查看文件

@@ -146,3 +146,6 @@ TIMEZONE='Asia/Shanghai'
# ENDPOINT=http://oss-cn-hangzhou.aliyuncs.com
# REGION=cn-hangzhou
# BUCKET=ragflow65536

# user registration switch
REGISTER_ENABLED=1

+ 2
- 0
web/src/hooks/login-hooks.ts 查看文件

@@ -67,6 +67,8 @@ export const useRegister = () => {
const { data = {} } = await userService.register(params);
if (data.code === 0) {
message.success(t('message.registered'));
} else if (data.message && data.message.includes('registration is disabled')) {
message.error(t('message.registerDisabled') || 'User registration is disabled');
}
return data.code;
},

+ 18
- 0
web/src/hooks/system-hooks.ts 查看文件

@@ -0,0 +1,18 @@
import userService from '@/services/user-service';
import { useQuery } from '@tanstack/react-query';

/**
* Hook to fetch system configuration including register enable status
* @returns System configuration with loading status
*/
export const useSystemConfig = () => {
const { data, isLoading } = useQuery({
queryKey: ['systemConfig'],
queryFn: async () => {
const { data = {} } = await userService.getSystemConfig();
return data.data || { registerEnabled: 1 }; // Default to enabling registration
},
});

return { config: data, loading: isLoading };
};

+ 1
- 0
web/src/locales/en.ts 查看文件

@@ -705,6 +705,7 @@ This auto-tag feature enhances retrieval by adding another layer of domain-speci
logout: 'logout',
logged: 'logged!',
pleaseSelectChunk: 'Please select chunk!',
registerDisabled: 'User registration is disabled',
modified: 'Modified',
created: 'Created',
deleted: 'Deleted',

+ 7
- 1
web/src/pages/login/index.tsx 查看文件

@@ -1,4 +1,5 @@
import { useLogin, useRegister } from '@/hooks/login-hooks';
import { useSystemConfig } from '@/hooks/system-hooks';
import { rsaPsw } from '@/utils';
import { Button, Checkbox, Form, Input } from 'antd';
import { useEffect, useState } from 'react';
@@ -16,8 +17,13 @@ const Login = () => {
const { register, loading: registerLoading } = useRegister();
const { t } = useTranslation('translation', { keyPrefix: 'login' });
const loading = signLoading || registerLoading;
const { config } = useSystemConfig();
const registerEnabled = config?.registerEnabled !== 0;

const changeTitle = () => {
if (title === 'login' && !registerEnabled) {
return;
}
setTitle((title) => (title === 'login' ? 'register' : 'login'));
};
const [form] = Form.useForm();
@@ -119,7 +125,7 @@ const Login = () => {
</Form.Item>
)}
<div>
{title === 'login' && (
{title === 'login' && registerEnabled && (
<div>
{t('signInTip')}
<Button type="link" onClick={changeTitle}>

+ 5
- 0
web/src/services/user-service.ts 查看文件

@@ -22,6 +22,7 @@ const {
getSystemTokenList,
removeSystemToken,
createSystemToken,
getSystemConfig,
} = api;

const methods = {
@@ -101,6 +102,10 @@ const methods = {
url: removeSystemToken,
method: 'delete',
},
getSystemConfig: {
url: getSystemConfig,
method: 'get',
},
} as const;

const userService = registerServer<keyof typeof methods>(methods, request);

+ 1
- 0
web/src/utils/api.ts 查看文件

@@ -119,6 +119,7 @@ export default {
createSystemToken: `${api_host}/system/new_token`,
listSystemToken: `${api_host}/system/token_list`,
removeSystemToken: `${api_host}/system/token`,
getSystemConfig: `${api_host}/system/config`,

// flow
listTemplates: `${api_host}/canvas/templates`,

Loading…
取消
儲存