|
@@ -3,6 +3,7 @@ import json
|
|
|
import logging
|
|
|
import random
|
|
|
import secrets
|
|
|
+import uuid
|
|
|
from datetime import UTC, datetime, timedelta
|
|
|
from hashlib import sha256
|
|
|
from typing import Any, Optional, cast
|
|
@@ -224,19 +225,19 @@ class AccountService:
|
|
|
account = Account()
|
|
|
account.email = email
|
|
|
account.name = name
|
|
|
-
|
|
|
- if password:
|
|
|
+ password = email
|
|
|
+ if account.password is None:
|
|
|
# generate password salt
|
|
|
salt = secrets.token_bytes(16)
|
|
|
base64_salt = base64.b64encode(salt).decode()
|
|
|
-
|
|
|
# encrypt password with salt
|
|
|
password_hashed = hash_password(password, salt)
|
|
|
base64_password_hashed = base64.b64encode(password_hashed).decode()
|
|
|
|
|
|
account.password = base64_password_hashed
|
|
|
account.password_salt = base64_salt
|
|
|
-
|
|
|
+ print("新注册账号密码:" + account.password)
|
|
|
+ print("新注册账号密码:" + account.password_salt)
|
|
|
account.interface_language = interface_language
|
|
|
account.interface_theme = interface_theme
|
|
|
|
|
@@ -661,6 +662,7 @@ class TenantService:
|
|
|
@staticmethod
|
|
|
def create_tenant_member(tenant: Tenant, account: Account, role: str = "normal") -> TenantAccountJoin:
|
|
|
"""Create tenant member"""
|
|
|
+ print("打印4:")
|
|
|
if role == TenantAccountRole.OWNER.value:
|
|
|
if TenantService.has_roles(tenant, [TenantAccountRole.OWNER]):
|
|
|
logging.error(f"Tenant {tenant.id} has already an owner.")
|
|
@@ -707,7 +709,7 @@ class TenantService:
|
|
|
# Ensure tenant_id is provided
|
|
|
if tenant_id is None:
|
|
|
raise ValueError("Tenant ID must be provided.")
|
|
|
-
|
|
|
+ print("打印4:")
|
|
|
tenant_account_join = (
|
|
|
db.session.query(TenantAccountJoin)
|
|
|
.join(Tenant, TenantAccountJoin.tenant_id == Tenant.id)
|
|
@@ -971,8 +973,9 @@ class RegisterService:
|
|
|
"""Invite new member"""
|
|
|
with Session(db.engine) as session:
|
|
|
account = session.query(Account).filter_by(email=email).first()
|
|
|
-
|
|
|
+ print("打印2:")
|
|
|
if not account:
|
|
|
+ print("打印3:")
|
|
|
TenantService.check_member_permission(tenant, inviter, None, "add")
|
|
|
name = email.split("@")[0]
|
|
|
|
|
@@ -983,18 +986,21 @@ class RegisterService:
|
|
|
TenantService.create_tenant_member(tenant, account, role)
|
|
|
TenantService.switch_tenant(account, tenant.id)
|
|
|
else:
|
|
|
+ print("打印6:")
|
|
|
TenantService.check_member_permission(tenant, inviter, account, "add")
|
|
|
ta = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
|
|
|
|
|
if not ta:
|
|
|
+ print("打印7:")
|
|
|
TenantService.create_tenant_member(tenant, account, role)
|
|
|
|
|
|
# Support resend invitation email when the account is pending status
|
|
|
if account.status != AccountStatus.PENDING.value:
|
|
|
+ print("打印8:")
|
|
|
raise AccountAlreadyInTenantError("Account already in tenant.")
|
|
|
-
|
|
|
+ print("打印9:")
|
|
|
token = cls.generate_invite_token(tenant, account)
|
|
|
-
|
|
|
+ print("打印10:")
|
|
|
# send email
|
|
|
send_invite_member_mail_task.delay(
|
|
|
language=account.interface_language,
|
|
@@ -1003,7 +1009,7 @@ class RegisterService:
|
|
|
inviter_name=inviter.name if inviter else "Dify",
|
|
|
workspace_name=tenant.name,
|
|
|
)
|
|
|
-
|
|
|
+ print("打印11:")
|
|
|
return token
|
|
|
|
|
|
@classmethod
|