Révision 78775031
Ajouté par Serghei Mihai il y a presque 8 ans
corbo/settings.py | ||
---|---|---|
107 | 107 |
# default mass emails expeditor |
108 | 108 |
CORBO_DEFAULT_FROM_EMAIL = 'webmaster@localhost' |
109 | 109 |
|
110 |
# django-mellon settings |
|
110 |
|
|
111 |
# Authentication settings |
|
112 |
try: |
|
113 |
import mellon |
|
114 |
except ImportError: |
|
115 |
mellon = None |
|
116 |
|
|
117 |
if mellon is not None: |
|
118 |
AUTHENTICATION_BACKENDS = ( |
|
119 |
'mellon.backends.SAMLBackend', |
|
120 |
'django.contrib.auth.backends.ModelBackend', |
|
121 |
) |
|
122 |
|
|
123 |
LOGIN_URL = '/login/' |
|
124 |
LOGIN_REDIRECT_URL = '/' |
|
125 |
LOGOUT_URL = '/logout/' |
|
126 |
|
|
111 | 127 |
MELLON_ATTRIBUTE_MAPPING = { |
112 |
'username': '{attributes[username][0]}', |
|
113 | 128 |
'email': '{attributes[email][0]}', |
114 | 129 |
'first_name': '{attributes[first_name][0]}', |
115 | 130 |
'last_name': '{attributes[last_name][0]}', |
116 | 131 |
} |
117 | 132 |
|
118 |
if 'mellon' in INSTALLED_APPS: |
|
119 |
AUTHENTICATION_BACKENDS = ('mellon.backends.SAMLBackend', ) |
|
120 |
LOGIN_URL = 'mellon_login' |
|
121 |
LOGOUT_URL = 'mellon_logout' |
|
133 |
MELLON_SUPERUSER_MAPPING = { |
|
134 |
'is_superuser': 'true', |
|
135 |
} |
|
136 |
|
|
137 |
MELLON_USERNAME_TEMPLATE = '{attributes[name_id_content]}' |
|
138 |
|
|
139 |
MELLON_IDENTITY_PROVIDERS = [] |
|
122 | 140 |
|
123 | 141 |
local_settings_file = os.environ.get('CORBO_SETTINGS_FILE', |
124 | 142 |
os.path.join(os.path.dirname(__file__), 'local_settings.py')) |
corbo/templates/corbo/base.html | ||
---|---|---|
7 | 7 |
{% endblock %} |
8 | 8 |
|
9 | 9 |
{% block logout-url %} |
10 |
{% url "logout" %} |
|
10 |
{% url "auth_logout" %}
|
|
11 | 11 |
{% endblock %} |
12 | 12 |
|
13 | 13 |
{% block site-title %} {% trans "Announces" %}{% endblock %} |
corbo/urls.py | ||
---|---|---|
5 | 5 |
from django.contrib import admin |
6 | 6 |
|
7 | 7 |
from .urls_utils import decorated_includes, manager_required |
8 |
from .views import homepage, atom, unsubscribe, unsubscription_done |
|
8 |
from .views import homepage, atom, unsubscribe, unsubscription_done, login, logout
|
|
9 | 9 |
|
10 | 10 |
from manage_urls import urlpatterns as manage_urls |
11 | 11 |
from api_urls import urlpatterns as api_urls |
... | ... | |
22 | 22 |
name='unsubscription_done'), |
23 | 23 |
url(r'^unsubscribe/(?P<unsubscription_token>[\w:-]+)$', unsubscribe, |
24 | 24 |
name='unsubscribe'), |
25 |
url(r'^logout/$', logout, name='auth_logout'), |
|
26 |
url(r'^login/$', login, name='auth_login'), |
|
25 | 27 |
) |
26 | 28 |
|
27 | 29 |
if 'mellon' in settings.INSTALLED_APPS: |
28 |
# authentication with django-mellon |
|
29 |
urlpatterns += patterns('', |
|
30 |
url(r'^accounts/mellon/', include('mellon.urls')), |
|
31 |
) |
|
32 |
else: |
|
33 |
urlpatterns += patterns('', |
|
34 |
url('^accounts/', include('django.contrib.auth.urls')), |
|
35 |
) |
|
36 |
|
|
30 |
urlpatterns += patterns('', url(r'^accounts/mellon/', include('mellon.urls'))) |
|
37 | 31 |
|
38 | 32 |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
39 | 33 |
urlpatterns += staticfiles_urlpatterns() |
corbo/views.py | ||
---|---|---|
1 | 1 |
from datetime import datetime |
2 |
import urllib |
|
2 | 3 |
|
3 | 4 |
from django.conf import settings |
4 | 5 |
from django.core import signing |
... | ... | |
6 | 7 |
from django.views.generic import CreateView, UpdateView, DeleteView, \ |
7 | 8 |
ListView, TemplateView |
8 | 9 |
from django.contrib.syndication.views import Feed |
10 |
from django.shortcuts import resolve_url |
|
9 | 11 |
from django.utils.feedgenerator import Atom1Feed |
10 | 12 |
from django.utils.http import urlencode |
11 | 13 |
from django.http import Http404 |
14 |
from django.contrib.auth import logout as auth_logout |
|
15 |
from django.contrib.auth import views as auth_views |
|
16 |
from django.http import HttpResponseRedirect |
|
12 | 17 |
|
13 | 18 |
import models |
14 | 19 |
from .forms import AnnounceForm, CategoryForm |
15 | 20 |
|
21 |
try: |
|
22 |
from mellon.utils import get_idps |
|
23 |
except ImportError: |
|
24 |
get_idps = lambda: [] |
|
25 |
|
|
26 |
def login(request, *args, **kwargs): |
|
27 |
if any(get_idps()): |
|
28 |
if not 'next' in request.GET: |
|
29 |
return HttpResponseRedirect(resolve_url('mellon_login')) |
|
30 |
return HttpResponseRedirect(resolve_url('mellon_login') + '?next=' |
|
31 |
+ urllib.quote(request.GET.get('next'))) |
|
32 |
return auth_views.login(request, *args, **kwargs) |
|
33 |
|
|
34 |
def logout(request, next_page=None): |
|
35 |
if any(get_idps()): |
|
36 |
return HttpResponseRedirect(resolve_url('mellon_logout')) |
|
37 |
auth_logout(request) |
|
38 |
if next_page is not None: |
|
39 |
next_page = resolve_url(next_page) |
|
40 |
else: |
|
41 |
next_page = '/' |
|
42 |
return HttpResponseRedirect(next_page) |
|
43 |
|
|
44 |
|
|
16 | 45 |
class HomepageView(ListView): |
17 | 46 |
model = models.Announce |
18 | 47 |
template_name = 'corbo/homepage.html' |
Formats disponibles : Unified diff
authentication views fix