ran reformat

pull/22390/head
Yansong Zhang 11 months ago
parent f365677fd5
commit 227eac79c8

@ -30,11 +30,13 @@ class PasswordResetRateLimitExceededError(BaseHTTPException):
description = "Too many password reset emails have been sent. Please try again in 1 minutes."
code = 429
class EmailChangeRateLimitExceededError(BaseHTTPException):
error_code = "email_change_rate_limit_exceeded"
description = "Too many email change emails have been sent. Please try again in 1 minutes."
code = 429
class EmailCodeError(BaseHTTPException):
error_code = "email_code_error"
description = "Email code is invalid or expired."
@ -70,11 +72,13 @@ class EmailPasswordResetLimitError(BaseHTTPException):
description = "Too many failed password reset attempts. Please try again in 24 hours."
code = 429
class EmailChangeLimitError(BaseHTTPException):
error_code = "email_change_limit"
description = "Too many failed email change attempts. Please try again in 24 hours."
code = 429
class EmailAlreadyInUseError(BaseHTTPException):
error_code = "email_already_in_use"
description = "A user with this email already exists."

@ -11,11 +11,11 @@ from configs import dify_config
from constants.languages import supported_language
from controllers.console import api
from controllers.console.auth.error import (
EmailAlreadyInUseError,
EmailChangeLimitError,
EmailCodeError,
InvalidEmailError,
InvalidTokenError,
EmailAlreadyInUseError,
)
from controllers.console.error import AccountNotFound, EmailSendIpLimitError
from controllers.console.workspace.error import (
@ -380,6 +380,7 @@ class EducationAutoCompleteApi(Resource):
return BillingService.EducationIdentity.autocomplete(args["keywords"], args["page"], args["limit"])
class ChangeEmailSendEmailApi(Resource):
@enable_change_email
@setup_required
@ -420,7 +421,9 @@ class ChangeEmailSendEmailApi(Resource):
if account is None:
raise AccountNotFound()
token = AccountService.send_change_email_email(account=account, email=args["email"], old_email=user_email, language=language, phase=args["phase"]) # noqa: E501
token = AccountService.send_change_email_email(
account=account, email=args["email"], old_email=user_email, language=language, phase=args["phase"]
) # noqa: E501
return {"result": "success", "data": token}
@ -464,6 +467,7 @@ class ChangeEmailCheckApi(Resource):
AccountService.reset_change_email_error_rate_limit(args["email"])
return {"is_valid": True, "email": token_data.get("email"), "token": new_token}
class ChangeEmailResetApi(Resource):
@enable_change_email
@setup_required
@ -493,6 +497,7 @@ class ChangeEmailResetApi(Resource):
return updated_account
class CheckEmailUnique(Resource):
@setup_required
def post(self):
@ -506,6 +511,7 @@ class CheckEmailUnique(Resource):
raise EmailAlreadyInUseError()
return {"result": "success"}
# Register API resources
api.add_resource(AccountInitApi, "/account/init")
api.add_resource(AccountProfileApi, "/account/profile")

@ -236,6 +236,7 @@ def email_password_login_enabled(view):
return decorated
def enable_change_email(view):
@wraps(view)
def decorated(*args, **kwargs):
@ -245,4 +246,5 @@ def enable_change_email(view):
# otherwise, return 403
abort(403)
return decorated

@ -76,9 +76,7 @@ class AccountService:
email_code_account_deletion_rate_limiter = RateLimiter(
prefix="email_code_account_deletion_rate_limit", max_attempts=1, time_window=60 * 1
)
change_email_rate_limiter = RateLimiter(
prefix="change_email_rate_limit", max_attempts=2, time_window=60 * 1
)
change_email_rate_limiter = RateLimiter(prefix="change_email_rate_limit", max_attempts=1, time_window=60 * 1)
LOGIN_MAX_ERROR_LIMITS = 5
FORGOT_PASSWORD_MAX_ERROR_LIMITS = 5
CHANGE_EMAIL_MAX_ERROR_LIMITS = 5

Loading…
Cancel
Save