Skip to content

Commit

Permalink
added backwards compatibility when LOGIN_URL == LOGOUT_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Mijnhout committed Jan 11, 2019
1 parent acd00ad commit 673475a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,11 @@ def get_context_data(self, **kwargs):
return context

def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
# If the logout url is the login url, log the user out of the system
if settings.LOGOUT_URL == settings.LOGIN_URL:
logout(request)
# Else redirect a logged in user to the homepage
elif request.user.is_authenticated:
return redirect("/")
return super(LoginView, self).get(request, *args, **kwargs)

Expand Down
4 changes: 4 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ Being a pure Django settings, LOGIN_URL and LOGOUT_URL used in Arctic to display
login and logout links. Both items supposed to be names of URLs. Defaults are 'login'
and 'logout'. Could be set to `None` if you don't want to use authentication in your app.

If the LOGIN_URL and LOGOUT_URL are the same, the LoginView will automatically logout
the user when he visits the login page. If they are different, a logged in user will be
redirected to the homepage of the CMS and not be logged out.

# Generic Class Based Views

Arctic provides a number of class based views that add integration with the
Expand Down

0 comments on commit 673475a

Please sign in to comment.