Skip to content

Commit

Permalink
Merge acd00ad into 4041575
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Mijnhout committed Jan 11, 2019
2 parents 4041575 + acd00ad commit cae6de3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Always reference the ticket number at the end of the issue description.

## Pending

### Fixed

- Do not logout logged-in users which visit the login view, but redirect them to home

## 1.3.5 (2018-12-21)

Expand Down
9 changes: 8 additions & 1 deletion arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ def get_context_data(self, **kwargs):
return context

def get(self, request, *args, **kwargs):
logout(request)
if request.user.is_authenticated:
return redirect("/")
return super(LoginView, self).get(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
Expand All @@ -932,3 +933,9 @@ def post(self, request, *args, **kwargs):
return render(
request, self.template_name, self.get_context_data(**kwargs)
)


class LogoutView(View):
def dispatch(self, request, *args, **kwargs):
logout(request)
return redirect(settings.LOGIN_URL)
3 changes: 2 additions & 1 deletion arctic/project_template/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@

STATIC_URL = "/static/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"

# Arctic configuration
ARCTIC_SITE_NAME = "{{ project_name }}'s Arctic website"
Expand Down
3 changes: 2 additions & 1 deletion example/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
MEDIA_ROOT = location("media")
MEDIA_URL = "/media/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"


try:
Expand Down
3 changes: 2 additions & 1 deletion example/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf.urls import include, url
from django.conf.urls.static import static

from arctic.generics import LoginView
from arctic.generics import LoginView, LogoutView
from arctic.views import handler400, handler403, handler404, handler500 # noqa

from countries.views import CountryAPIView, CountryListView
Expand All @@ -14,6 +14,7 @@
urlpatterns = [
url(r"^$", DashboardView.as_view(), name="index"),
url(r"^login/$", LoginView.as_view(), name="login"),
url(r"^logout/$", LogoutView.as_view(), name="logout"),
url(r"^articles/", include("articles.urls", "articles")),
url(r"^users/", include("arctic.users.urls", namespace="users")),
url(r"^countries/$", CountryListView.as_view(), name="countries-list"),
Expand Down

0 comments on commit cae6de3

Please sign in to comment.