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