mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-13 03:09:04 +08:00
Refactor user registration (#1970)
### What problem does this PR solve? 1. Refactor error message 2. Update function name ### Type of change - [x] Refactoring Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
parent
4810cb2dc9
commit
c9551b7f68
@ -32,7 +32,7 @@ from api.settings import RetCode, GITHUB_OAUTH, FEISHU_OAUTH, CHAT_MDL, EMBEDDIN
|
|||||||
from api.db.services.user_service import UserService, TenantService, UserTenantService
|
from api.db.services.user_service import UserService, TenantService, UserTenantService
|
||||||
from api.db.services.file_service import FileService
|
from api.db.services.file_service import FileService
|
||||||
from api.settings import stat_logger
|
from api.settings import stat_logger
|
||||||
from api.utils.api_utils import get_json_result, cors_reponse
|
from api.utils.api_utils import get_json_result, construct_response
|
||||||
|
|
||||||
|
|
||||||
@manager.route('/login', methods=['POST', 'GET'])
|
@manager.route('/login', methods=['POST', 'GET'])
|
||||||
@ -64,7 +64,7 @@ def login():
|
|||||||
user.update_date = datetime_format(datetime.now()),
|
user.update_date = datetime_format(datetime.now()),
|
||||||
user.save()
|
user.save()
|
||||||
msg = "Welcome back!"
|
msg = "Welcome back!"
|
||||||
return cors_reponse(data=response_data, auth=user.get_id(), retmsg=msg)
|
return construct_response(data=response_data, auth=user.get_id(), retmsg=msg)
|
||||||
else:
|
else:
|
||||||
return get_json_result(data=False, retcode=RetCode.AUTHENTICATION_ERROR,
|
return get_json_result(data=False, retcode=RetCode.AUTHENTICATION_ERROR,
|
||||||
retmsg='Email and Password do not match!')
|
retmsg='Email and Password do not match!')
|
||||||
@ -347,10 +347,12 @@ def user_add():
|
|||||||
retmsg=f'Email: {email_address} has already registered!',
|
retmsg=f'Email: {email_address} has already registered!',
|
||||||
retcode=RetCode.OPERATING_ERROR)
|
retcode=RetCode.OPERATING_ERROR)
|
||||||
|
|
||||||
|
# Construct user info data
|
||||||
|
nickname = req["nickname"]
|
||||||
user_dict = {
|
user_dict = {
|
||||||
"access_token": get_uuid(),
|
"access_token": get_uuid(),
|
||||||
"email": email_address,
|
"email": email_address,
|
||||||
"nickname": req["nickname"],
|
"nickname": nickname,
|
||||||
"password": decrypt(req["password"]),
|
"password": decrypt(req["password"]),
|
||||||
"login_channel": "password",
|
"login_channel": "password",
|
||||||
"last_login_time": get_format_time(),
|
"last_login_time": get_format_time(),
|
||||||
@ -361,18 +363,20 @@ def user_add():
|
|||||||
try:
|
try:
|
||||||
users = user_register(user_id, user_dict)
|
users = user_register(user_id, user_dict)
|
||||||
if not users:
|
if not users:
|
||||||
raise Exception('Register user failure.')
|
raise Exception(f'Fail to register {email_address}.')
|
||||||
if len(users) > 1:
|
if len(users) > 1:
|
||||||
raise Exception('Same E-mail exist!')
|
raise Exception(f'Same E-mail: {email_address} exists!')
|
||||||
user = users[0]
|
user = users[0]
|
||||||
login_user(user)
|
login_user(user)
|
||||||
return cors_reponse(data=user.to_json(),
|
return construct_response(data=user.to_json(),
|
||||||
auth=user.get_id(), retmsg="Welcome aboard!")
|
auth=user.get_id(),
|
||||||
|
retmsg=f"{nickname}, welcome aboard!")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
rollback_user_registration(user_id)
|
rollback_user_registration(user_id)
|
||||||
stat_logger.exception(e)
|
stat_logger.exception(e)
|
||||||
return get_json_result(
|
return get_json_result(data=False,
|
||||||
data=False, retmsg='User registration failure!', retcode=RetCode.EXCEPTION_ERROR)
|
retmsg=f'User registration failure, error: {str(e)}',
|
||||||
|
retcode=RetCode.EXCEPTION_ERROR)
|
||||||
|
|
||||||
|
|
||||||
@manager.route("/tenant_info", methods=["GET"])
|
@manager.route("/tenant_info", methods=["GET"])
|
||||||
|
@ -216,7 +216,7 @@ def get_json_result(retcode=RetCode.SUCCESS, retmsg='success', data=None):
|
|||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
|
|
||||||
def cors_reponse(retcode=RetCode.SUCCESS,
|
def construct_response(retcode=RetCode.SUCCESS,
|
||||||
retmsg='success', data=None, auth=None):
|
retmsg='success', data=None, auth=None):
|
||||||
result_dict = {"retcode": retcode, "retmsg": retmsg, "data": data}
|
result_dict = {"retcode": retcode, "retmsg": retmsg, "data": data}
|
||||||
response_dict = {}
|
response_dict = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user