Преглед на файлове

Feat/change user email freezes limit (#22900)

tags/1.7.1
zyssyz123 преди 3 месеца
родител
ревизия
6ac06486e3
No account linked to committer's email address
променени са 3 файла, в които са добавени 19 реда и са изтрити 3 реда
  1. 6
    0
      api/controllers/console/auth/error.py
  2. 7
    3
      api/controllers/console/workspace/account.py
  3. 6
    0
      api/services/account_service.py

+ 6
- 0
api/controllers/console/auth/error.py Целия файл

@@ -113,3 +113,9 @@ class MemberNotInTenantError(BaseHTTPException):
error_code = "member_not_in_tenant"
description = "The member is not in the workspace."
code = 400


class AccountInFreezeError(BaseHTTPException):
error_code = "account_in_freeze"
description = "This email is temporarily unavailable."
code = 400

+ 7
- 3
api/controllers/console/workspace/account.py Целия файл

@@ -9,6 +9,7 @@ from configs import dify_config
from constants.languages import supported_language
from controllers.console import api
from controllers.console.auth.error import (
AccountInFreezeError,
EmailAlreadyInUseError,
EmailChangeLimitError,
EmailCodeError,
@@ -479,15 +480,18 @@ class ChangeEmailResetApi(Resource):
parser.add_argument("token", type=str, required=True, nullable=False, location="json")
args = parser.parse_args()

if AccountService.is_account_in_freeze(args["new_email"]):
raise AccountInFreezeError()

if not AccountService.check_email_unique(args["new_email"]):
raise EmailAlreadyInUseError()

reset_data = AccountService.get_change_email_data(args["token"])
if not reset_data:
raise InvalidTokenError()

AccountService.revoke_change_email_token(args["token"])

if not AccountService.check_email_unique(args["new_email"]):
raise EmailAlreadyInUseError()

old_email = reset_data.get("old_email", "")
if current_user.email != old_email:
raise AccountNotFound()

+ 6
- 0
api/services/account_service.py Целия файл

@@ -671,6 +671,12 @@ class AccountService:

return account

@classmethod
def is_account_in_freeze(cls, email: str) -> bool:
if dify_config.BILLING_ENABLED and BillingService.is_email_in_freeze(email):
return True
return False

@staticmethod
@redis_fallback(default_return=None)
def add_login_error_rate_limit(email: str) -> None:

Loading…
Отказ
Запис