This commit is contained in:
yangqiyong 2025-03-21 13:34:57 +08:00 committed by GitHub
commit 4636a59e25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,7 @@ from flask import request
from flask_restful import Resource, reqparse # type: ignore from flask_restful import Resource, reqparse # type: ignore
from sqlalchemy import select from sqlalchemy import select
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from sqlalchemy.exc import SQLAlchemyError
from constants.languages import languages from constants.languages import languages
from controllers.console import api from controllers.console import api
from controllers.console.auth.error import ( from controllers.console.auth.error import (
@ -119,30 +119,41 @@ class ForgotPasswordResetApi(Resource):
password_hashed = hash_password(new_password, salt) password_hashed = hash_password(new_password, salt)
base64_password_hashed = base64.b64encode(password_hashed).decode() base64_password_hashed = base64.b64encode(password_hashed).decode()
with Session(db.engine) as session: try:
account = session.execute(select(Account).filter_by(email=reset_data.get("email"))).scalar_one_or_none() with Session(db.engine) as session:
if account: # Retrieve matching account information
account.password = base64_password_hashed account = session.execute(select(Account).filter_by(email=reset_data.get("email"))).scalar_one_or_none()
account.password_salt = base64_salt if account:
db.session.commit() # update account password and salt value.
tenant = TenantService.get_join_tenants(account) account.password = base64_password_hashed
if not tenant and not FeatureService.get_system_features().is_allow_create_workspace: account.password_salt = base64_salt
tenant = TenantService.create_tenant(f"{account.name}'s Workspace") session.commit()
TenantService.create_tenant_member(tenant, account, role="owner")
account.current_tenant = tenant # get the tenants joined by the account.
tenant_was_created.send(tenant) tenant = TenantService.get_join_tenants(account)
else:
try: # If the account has not joined a tenant and the system does not allow workspace creation, create a new tenant
account = AccountService.create_account_and_tenant( if not tenant and not FeatureService.get_system_features().is_allow_create_workspace:
email=reset_data.get("email", ""), tenant = TenantService.create_tenant(f"{account.name}'s Workspace")
name=reset_data.get("email", ""), TenantService.create_tenant_member(tenant, account, role="owner")
password=password_confirm, account.current_tenant = tenant
interface_language=languages[0], # send tenant creation event notification.
) tenant_was_created.send(tenant)
except WorkSpaceNotAllowedCreateError: else:
pass try:
except AccountRegisterError: account = AccountService.create_account_and_tenant(
raise AccountInFreezeError() email=reset_data.get("email", ""),
name=reset_data.get("email", ""),
password=password_confirm,
interface_language=languages[0],
)
except WorkSpaceNotAllowedCreateError:
pass
except AccountRegisterError:
raise AccountInFreezeError()
except SQLAlchemyError as e:
# handle database operation exceptions.
session.rollback()
return {"result": "success"} return {"result": "success"}