Skip to content

Commit

Permalink
Use a signal to set locale cookie after login
Browse files Browse the repository at this point in the history
Effectively undoes commit 0f8018e

The approach of signals is required because of social login. See issue
#171
for details as to why.
  • Loading branch information
giorgio93p committed Jan 20, 2020
1 parent 1a008c9 commit 22402dd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
3 changes: 2 additions & 1 deletion cjworkbench/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

# this line required to get ServerConfig.ready() to run
default_app_config = "cjworkbench.apps.ServerConfig"
2 changes: 1 addition & 1 deletion cjworkbench/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class ServerConfig(AppConfig):
name = "cjworkbench"

def ready(self):
pass
import cjworkbench.signals
8 changes: 8 additions & 0 deletions cjworkbench/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from allauth.account.signals import user_logged_in
from django.dispatch import receiver
from cjworkbench.i18n import set_language_cookie


@receiver(user_logged_in)
def set_locale_cookie_after_login(sender, *, response, user, **kwargs):
set_language_cookie(response, user.user_profile.locale_id)
2 changes: 0 additions & 2 deletions cjworkbench/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
from django.contrib import admin
from django.views.generic.base import RedirectView
from cjworkbench.i18n.views import set_locale
from cjworkbench.views.login import LoginView

urlpatterns = [
url(r"^admin/?", admin.site.urls),
url(r"^account/signup/$", SignupView.as_view(), name="account_signup"),
url(r"^account/login/$", LoginView.as_view(), name="account_login"),
url(
r"^xyzzy/signup/$",
RedirectView.as_view(url="/account/signup/", permanent=True),
Expand Down
10 changes: 0 additions & 10 deletions cjworkbench/views/login.py

This file was deleted.

0 comments on commit 22402dd

Please sign in to comment.