Skip to content

Commit

Permalink
feat: 更换用户被挤掉线的返回错误码
Browse files Browse the repository at this point in the history
  • Loading branch information
zgqgit committed Jul 2, 2024
1 parent 0b672f9 commit 4d5c889
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/backend/bisheng/api/errcode/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class UserPasswordError(BaseErrorCode):
Msg: str = '当前密码错误'


class UserLoginOfflineError(BaseErrorCode):
Code: int = 10604
Msg: str = '您的账户已在另一设备上登录,此设备上的会话已被注销。\n如果这不是您本人的操作,请尽快修改您的账户密码。'


class UserGroupNotDeleteError(BaseErrorCode):
Code: int = 10610
Msg: str = '用户组内还有用户,不能删除'
5 changes: 3 additions & 2 deletions src/backend/bisheng/api/services/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List

from bisheng.api.JWT import ACCESS_TOKEN_EXPIRE_TIME
from bisheng.api.errcode.user import UserLoginOfflineError
from bisheng.cache.redis import redis_client
from bisheng.database.models.assistant import Assistant, AssistantDao
from bisheng.database.models.flow import Flow, FlowDao, FlowRead
Expand Down Expand Up @@ -225,6 +226,6 @@ async def get_login_user(authorize: AuthJWT = Depends()) -> UserPayload:
current_token = redis_client.get(USER_CURRENT_SESSION.format(user.user_id))
# 登录被挤下线了,状态码是200, 内部的status_code是403
if current_token != authorize._token:
raise HTTPException(status_code=403,
detail='您的账户已在另一设备上登录,此设备上的会话已被注销。\n如果这不是您本人的操作,请尽快修改您的账户密码。')
raise HTTPException(status_code=UserLoginOfflineError.Code,
detail=UserLoginOfflineError.Msg)
return user

0 comments on commit 4d5c889

Please sign in to comment.