RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
add password reset function by extending the Flask command (#1632)
zhuhao792a1a9d9158
diff --git a/api/apps/__init__.py b/api/apps/__init__.pyindex 2034d08fc2..0c0ace7f0a 100644--- a/api/apps/__init__.py+++ b/api/apps/__init__.py@@ -25,7 +25,7 @@ from flask_cors import CORSfrom api.db import StatusEnumfrom api.db.db_models import close_connectionfrom api.db.services import UserService-from api.utils import CustomJSONEncoder+from api.utils import CustomJSONEncoder, commandsfrom flask_session import Sessionfrom flask_login import LoginManager@@ -60,6 +60,7 @@ Session(app)login_manager = LoginManager()login_manager.init_app(app)+commands.register_commands(app)def search_pages_path(pages_dir):diff --git a/api/utils/commands.py b/api/utils/commands.pynew file mode 100644index 0000000000..0ed184d9ad--- /dev/null+++ b/api/utils/commands.py@@ -0,0 +1,48 @@+#+# Copyright 2024 The InfiniFlow Authors. All Rights Reserved.+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+#++import base64+import click++from flask import Flask+from werkzeug.security import generate_password_hash++from api.db.services import UserService++[email protected]('reset-password', help='Reset the account password.')[email protected]('--email', prompt=True, help='The email address of the account whose password you need to reset')[email protected]('--new-password', prompt=True, help='the new password.')[email protected]('--password-confirm', prompt=True, help='the new password confirm.')+def reset_password(email, new_password, password_confirm):+ if str(new_password).strip() != str(password_confirm).strip():+ click.echo(click.style('sorry. The two passwords do not match.', fg='red'))+ return+ user = UserService.query(email=email)+ if not user:+ click.echo(click.style('sorry. The Email is not registered!.', fg='red'))+ return+ encode_password = base64.b64encode(new_password.encode('utf-8')).decode('utf-8')+ password_hash = generate_password_hash(encode_password)+ user_dict = {+ 'password': password_hash+ }+ UserService.update_user(user[0].id,user_dict)+ click.echo(click.style('Congratulations! Password has been reset.', fg='green'))+++def register_commands(app: Flask):+ app.cli.add_command(reset_password)\ No newline at end of file