|
|
|
@ -8,6 +8,11 @@ from datetime import UTC, datetime, timedelta
|
|
|
|
from hashlib import sha256
|
|
|
|
from hashlib import sha256
|
|
|
|
from typing import Any, Optional, cast
|
|
|
|
from typing import Any, Optional, cast
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel # type: ignore
|
|
|
|
|
|
|
|
from sqlalchemy import func # type: ignore
|
|
|
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
from werkzeug.exceptions import Unauthorized
|
|
|
|
|
|
|
|
|
|
|
|
from configs import dify_config
|
|
|
|
from configs import dify_config
|
|
|
|
from constants.languages import language_timezone_mapping, languages
|
|
|
|
from constants.languages import language_timezone_mapping, languages
|
|
|
|
from events.tenant_event import tenant_was_created
|
|
|
|
from events.tenant_event import tenant_was_created
|
|
|
|
@ -17,14 +22,21 @@ from libs.helper import RateLimiter, TokenManager
|
|
|
|
from libs.passport import PassportService
|
|
|
|
from libs.passport import PassportService
|
|
|
|
from libs.password import compare_password, hash_password, valid_password
|
|
|
|
from libs.password import compare_password, hash_password, valid_password
|
|
|
|
from libs.rsa import generate_key_pair
|
|
|
|
from libs.rsa import generate_key_pair
|
|
|
|
from models.account import (Account, AccountIntegrate, AccountStatus, Tenant,
|
|
|
|
from models.account import (
|
|
|
|
TenantAccountJoin, TenantAccountJoinRole,
|
|
|
|
Account,
|
|
|
|
TenantAccountRole, TenantStatus)
|
|
|
|
AccountIntegrate,
|
|
|
|
|
|
|
|
AccountStatus,
|
|
|
|
|
|
|
|
Tenant,
|
|
|
|
|
|
|
|
TenantAccountJoin,
|
|
|
|
|
|
|
|
TenantAccountRole,
|
|
|
|
|
|
|
|
TenantStatus,
|
|
|
|
|
|
|
|
)
|
|
|
|
from models.model import DifySetup
|
|
|
|
from models.model import DifySetup
|
|
|
|
from pydantic import BaseModel # type: ignore
|
|
|
|
|
|
|
|
from services.billing_service import BillingService
|
|
|
|
from services.billing_service import BillingService
|
|
|
|
from services.errors.account import (AccountAlreadyInTenantError,
|
|
|
|
from services.errors.account import (
|
|
|
|
AccountLoginError, AccountNotFoundError,
|
|
|
|
AccountAlreadyInTenantError,
|
|
|
|
|
|
|
|
AccountLoginError,
|
|
|
|
|
|
|
|
AccountNotFoundError,
|
|
|
|
AccountNotLinkTenantError,
|
|
|
|
AccountNotLinkTenantError,
|
|
|
|
AccountPasswordError,
|
|
|
|
AccountPasswordError,
|
|
|
|
AccountRegisterError,
|
|
|
|
AccountRegisterError,
|
|
|
|
@ -32,21 +44,19 @@ from services.errors.account import (AccountAlreadyInTenantError,
|
|
|
|
CurrentPasswordIncorrectError,
|
|
|
|
CurrentPasswordIncorrectError,
|
|
|
|
InvalidActionError,
|
|
|
|
InvalidActionError,
|
|
|
|
LinkAccountIntegrateError,
|
|
|
|
LinkAccountIntegrateError,
|
|
|
|
MemberNotInTenantError, NoPermissionError,
|
|
|
|
MemberNotInTenantError,
|
|
|
|
|
|
|
|
NoPermissionError,
|
|
|
|
RoleAlreadyAssignedError,
|
|
|
|
RoleAlreadyAssignedError,
|
|
|
|
TenantNotFoundError)
|
|
|
|
TenantNotFoundError,
|
|
|
|
|
|
|
|
)
|
|
|
|
from services.errors.workspace import WorkSpaceNotAllowedCreateError
|
|
|
|
from services.errors.workspace import WorkSpaceNotAllowedCreateError
|
|
|
|
from services.feature_service import FeatureService
|
|
|
|
from services.feature_service import FeatureService
|
|
|
|
from sqlalchemy import func # type: ignore
|
|
|
|
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
|
|
|
|
from tasks.delete_account_task import delete_account_task
|
|
|
|
from tasks.delete_account_task import delete_account_task
|
|
|
|
from tasks.mail_account_deletion_task import \
|
|
|
|
from tasks.mail_account_deletion_task import send_account_deletion_verification_code
|
|
|
|
send_account_deletion_verification_code
|
|
|
|
|
|
|
|
from tasks.mail_email_code_login import send_email_code_login_mail_task
|
|
|
|
from tasks.mail_email_code_login import send_email_code_login_mail_task
|
|
|
|
from tasks.mail_invite_member_task import send_invite_member_mail_task
|
|
|
|
from tasks.mail_invite_member_task import send_invite_member_mail_task
|
|
|
|
from tasks.mail_reset_password_task import send_reset_password_mail_task
|
|
|
|
from tasks.mail_reset_password_task import send_reset_password_mail_task
|
|
|
|
from tasks.phone_sms_code_login import send_phone_sms_code_login_task
|
|
|
|
from tasks.phone_sms_code_login import send_phone_sms_code_login_task
|
|
|
|
from werkzeug.exceptions import Unauthorized
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TokenPair(BaseModel):
|
|
|
|
class TokenPair(BaseModel):
|
|
|
|
@ -295,8 +305,7 @@ class AccountService:
|
|
|
|
def send_account_deletion_verification_email(cls, account: Account, code: str):
|
|
|
|
def send_account_deletion_verification_email(cls, account: Account, code: str):
|
|
|
|
email = account.email
|
|
|
|
email = account.email
|
|
|
|
if cls.email_code_account_deletion_rate_limiter.is_rate_limited(email):
|
|
|
|
if cls.email_code_account_deletion_rate_limiter.is_rate_limited(email):
|
|
|
|
from controllers.console.auth.error import \
|
|
|
|
from controllers.console.auth.error import EmailCodeAccountDeletionRateLimitExceededError
|
|
|
|
EmailCodeAccountDeletionRateLimitExceededError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise EmailCodeAccountDeletionRateLimitExceededError()
|
|
|
|
raise EmailCodeAccountDeletionRateLimitExceededError()
|
|
|
|
|
|
|
|
|
|
|
|
@ -434,8 +443,7 @@ class AccountService:
|
|
|
|
raise ValueError("Email must be provided.")
|
|
|
|
raise ValueError("Email must be provided.")
|
|
|
|
|
|
|
|
|
|
|
|
if cls.reset_password_rate_limiter.is_rate_limited(account_email):
|
|
|
|
if cls.reset_password_rate_limiter.is_rate_limited(account_email):
|
|
|
|
from controllers.console.auth.error import \
|
|
|
|
from controllers.console.auth.error import PasswordResetRateLimitExceededError
|
|
|
|
PasswordResetRateLimitExceededError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise PasswordResetRateLimitExceededError()
|
|
|
|
raise PasswordResetRateLimitExceededError()
|
|
|
|
|
|
|
|
|
|
|
|
@ -487,8 +495,7 @@ class AccountService:
|
|
|
|
if dify_config.DEBUG_CODE_FOR_LOGIN:
|
|
|
|
if dify_config.DEBUG_CODE_FOR_LOGIN:
|
|
|
|
code = dify_config.DEBUG_CODE_FOR_LOGIN
|
|
|
|
code = dify_config.DEBUG_CODE_FOR_LOGIN
|
|
|
|
elif cls.email_code_login_rate_limiter.is_rate_limited(email):
|
|
|
|
elif cls.email_code_login_rate_limiter.is_rate_limited(email):
|
|
|
|
from controllers.console.auth.error import \
|
|
|
|
from controllers.console.auth.error import EmailCodeLoginRateLimitExceededError
|
|
|
|
EmailCodeLoginRateLimitExceededError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
raise EmailCodeLoginRateLimitExceededError()
|
|
|
|
raise EmailCodeLoginRateLimitExceededError()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|