Skip to content

Commit fb4193b

Browse files
committed
refactor: enhance token generation for portal users using ChatToken
1 parent b8fc704 commit fb4193b

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎apps/portal/serializers/portal.py‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
import json
1111
import uuid_utils.compat as uuid
12-
from django.core import signing
1312
from django.core.cache import cache
1413
from django.utils.translation import gettext_lazy as _
1514
from rest_framework import serializers
1615

16+
from common.auth.common import ChatToken
17+
from common.auth.constants.operate_constants import Operate
18+
from common.constants.authentication_type import AuthenticationType
1719
from common.constants.cache_version import Cache_Version
1820
from common.database_model_manage.database_model_manage import DatabaseModelManage
1921
from common.exception.app_exception import AppApiException
@@ -183,14 +185,8 @@ def login(instance):
183185
cache.delete(cache_key, version=system_version)
184186
cache.delete(system_get_key(f"portal_{username}_lock"), version=system_version)
185187

186-
token = signing.dumps(
187-
{
188-
"username": user.username,
189-
"id": str(user.id),
190-
"type": "PORTAL_USER",
191-
}
192-
)
193-
version, get_key = Cache_Version.TOKEN.value
188+
token = ChatToken(str(user.id), AuthenticationType.CHAT_USER, str(Operate.LOCAL)).to_token()
189+
version, get_key = Cache_Version.CHAT_USER_TOKEN.value
194190
timeout = CONFIG.get_session_timeout()
195191
cache.set(get_key(token), user, timeout=timeout, version=version)
196192
record_log(

0 commit comments

Comments
 (0)