修复密码重置后,数据库未更新问题
This commit is contained in:
parent
b541792465
commit
a7239b17f4
@ -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:
|
# 查询匹配的账户信息
|
||||||
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()
|
# 更新账户密码和盐值
|
||||||
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
|
# 获取账户加入的租户
|
||||||
tenant_was_created.send(tenant)
|
tenant = TenantService.get_join_tenants(account)
|
||||||
else:
|
|
||||||
try:
|
# 如果账户没有加入租户且系统不允许创建工作区,则创建新租户
|
||||||
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],
|
# 发送租户创建事件通知
|
||||||
)
|
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:
|
||||||
|
# 处理数据库操作异常
|
||||||
|
session.rollback() # 回滚事务
|
||||||
|
|
||||||
return {"result": "success"}
|
return {"result": "success"}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user