Minor changes
Introduce new settings: - ACCOUNT_HOME_URL, used by 'Site name' link on templates. - ACCOUNT_DETAILS_URL, used on templates when user is connected. 'username' is registered as extra_data too for Clipper provider. Template tag 'get_accounts_by_providers' is cleaner. Remove useless account/settings view. Its content should be displayed by some profile view. SOCIALACCOUNT_ENABLED settings (of allauth package) doesn't work well. Template tag 'is_socialaccount_enabled' provides a better check.
This commit is contained in:
parent
e66920ed4e
commit
7932da906e
5 changed files with 53 additions and 21 deletions
|
@ -35,6 +35,7 @@ class ClipperProvider(CASProvider):
|
||||||
|
|
||||||
def extract_extra_data(self, data):
|
def extract_extra_data(self, data):
|
||||||
extra = super(ClipperProvider, self).extract_extra_data(data)
|
extra = super(ClipperProvider, self).extract_extra_data(data)
|
||||||
|
extra['username'] = data[0]
|
||||||
extra['email'] = self.extract_email(data)
|
extra['email'] = self.extract_email(data)
|
||||||
return extra
|
return extra
|
||||||
|
|
||||||
|
|
24
allauth_ens/templatetags/allauth_ens.py
Normal file
24
allauth_ens/templatetags/allauth_ens.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import django
|
||||||
|
from django import template
|
||||||
|
from django.conf import settings
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
if django.VERSION >= (1, 9):
|
||||||
|
simple_tag = register.simple_tag
|
||||||
|
else:
|
||||||
|
simple_tag = register.assignment_tag
|
||||||
|
|
||||||
|
|
||||||
|
@simple_tag
|
||||||
|
def get_home_url():
|
||||||
|
home_url = getattr(settings, 'ACCOUNT_HOME_URL', None)
|
||||||
|
return reverse(home_url) if home_url is not None else '/'
|
||||||
|
|
||||||
|
|
||||||
|
@simple_tag
|
||||||
|
def get_profile_url():
|
||||||
|
profile_url = getattr(settings, 'ACCOUNT_DETAILS_URL', None)
|
||||||
|
return reverse(profile_url) if profile_url is not None else '/'
|
|
@ -1,6 +1,9 @@
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
import django
|
import django
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
|
from allauth import app_settings as allauth_settings
|
||||||
from allauth.socialaccount.templatetags import socialaccount as tt_social
|
from allauth.socialaccount.templatetags import socialaccount as tt_social
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,16 +16,18 @@ else:
|
||||||
|
|
||||||
|
|
||||||
@simple_tag
|
@simple_tag
|
||||||
def get_providers_with_accounts(user):
|
def is_socialaccount_enabled():
|
||||||
|
return allauth_settings.SOCIALACCOUNT_ENABLED and tt_social.get_providers()
|
||||||
|
|
||||||
|
|
||||||
|
@simple_tag
|
||||||
|
def get_accounts_by_providers(user):
|
||||||
providers = tt_social.get_providers()
|
providers = tt_social.get_providers()
|
||||||
accounts = tt_social.get_social_accounts(user)
|
accounts = tt_social.get_social_accounts(user)
|
||||||
|
|
||||||
providers_with_accounts = [
|
providers_with_accounts = OrderedDict(
|
||||||
{
|
(provider, accounts.get(provider.id, []))
|
||||||
'provider': provider,
|
|
||||||
'accounts': accounts.get(provider.id, []),
|
|
||||||
}
|
|
||||||
for provider in providers
|
for provider in providers
|
||||||
]
|
)
|
||||||
|
|
||||||
return providers_with_accounts
|
return providers_with_accounts
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
from django.conf.urls import include, url
|
from allauth.urls import urlpatterns as allauth_urlpatterns
|
||||||
from . import views
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = allauth_urlpatterns
|
||||||
url(r'^settings/$', views.account_settings,
|
|
||||||
name="account_settings"),
|
|
||||||
url(r'^', include('allauth.urls')),
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.core.urlresolvers import reverse_lazy
|
||||||
from django.utils.decorators import method_decorator
|
from django.views.generic import RedirectView
|
||||||
from django.views.generic import TemplateView
|
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name="dispatch")
|
class CaptureLogin(RedirectView):
|
||||||
class SettingsAccount(TemplateView):
|
url = reverse_lazy('account_login')
|
||||||
template_name = 'account/settings.html'
|
query_string = True
|
||||||
|
|
||||||
|
|
||||||
account_settings = SettingsAccount.as_view()
|
capture_login = CaptureLogin.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
class CaptureLogout(RedirectView):
|
||||||
|
url = reverse_lazy('account_logout')
|
||||||
|
query_string = True
|
||||||
|
|
||||||
|
|
||||||
|
capture_logout = CaptureLogout.as_view()
|
||||||
|
|
Loading…
Reference in a new issue