Skip to content

Commit

Permalink
optimize generate-user-auth-token api (#5901)
Browse files Browse the repository at this point in the history
  • Loading branch information
likesclever authored Jan 18, 2024
1 parent d08f058 commit 8756a97
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions seahub/api2/endpoints/admin/generate_user_auth_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.utils import api_error, get_token_v1
from seahub.auth.utils import get_virtual_id_by_email

from seahub.base.accounts import User

Expand All @@ -30,8 +31,9 @@ def post(self, request):
error_msg = 'email invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

vid = get_virtual_id_by_email(email)
try:
user = User.objects.get(email=email)
user = User.objects.get(email=vid)
except User.DoesNotExist:
error_msg = 'User %s not found.' % email
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
Expand All @@ -41,7 +43,7 @@ def post(self, request):
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

try:
token = get_token_v1(email)
token = get_token_v1(user.username)
except Exception as e:
logger.error(e)
error_msg = 'Internal Server Error'
Expand Down

0 comments on commit 8756a97

Please sign in to comment.