Skip to content

Commit

Permalink
perf: update login success redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler authored and feng626 committed Dec 19, 2024
1 parent f6f8973 commit fab156d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions apps/authentication/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ def redirect_third_party_auth_if_need(self, request):
return redirect_url

def get(self, request, *args, **kwargs):
next_page = request.GET.get(self.redirect_field_name)
if next_page:
request.session[self.redirect_field_name] = next_page

if request.user.is_staff:
first_login_url = redirect_user_first_login_or_index(
request, self.redirect_field_name
Expand Down
10 changes: 7 additions & 3 deletions apps/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ def get_redirect_client_url(request):


def redirect_user_first_login_or_index(request, redirect_field_name):
url = request.POST.get(redirect_field_name)
if not url:
url = request.GET.get(redirect_field_name)
sources = [request.session, request.POST, request.GET]

url = ''
for source in sources:
url = source.get(redirect_field_name)
if url:
break

if url == 'client':
url = get_redirect_client_url(request)
Expand Down

0 comments on commit fab156d

Please sign in to comment.