add support for login/logout via django-mellon (#18725)
This commit is contained in:
parent
50c4cf330d
commit
af20754173
|
@ -107,6 +107,38 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
# Authentication settings
|
||||
try:
|
||||
import mellon
|
||||
except ImportError:
|
||||
mellon = None
|
||||
|
||||
if mellon is not None:
|
||||
INSTALLED_APPS += ('mellon',)
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'mellon.backends.SAMLBackend',
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
)
|
||||
|
||||
LOGIN_URL = '/login/'
|
||||
LOGIN_REDIRECT_URL = '/'
|
||||
LOGOUT_URL = '/logout/'
|
||||
|
||||
MELLON_ATTRIBUTE_MAPPING = {
|
||||
'email': '{attributes[email][0]}',
|
||||
'first_name': '{attributes[first_name][0]}',
|
||||
'last_name': '{attributes[last_name][0]}',
|
||||
}
|
||||
|
||||
MELLON_SUPERUSER_MAPPING = {
|
||||
'is_superuser': 'true',
|
||||
}
|
||||
|
||||
MELLON_USERNAME_TEMPLATE = '{attributes[name_id_content]}'
|
||||
|
||||
MELLON_IDENTITY_PROVIDERS = []
|
||||
|
||||
|
||||
|
||||
REDMINE_REFERENCE_PLATFORM = 'SaaS2 / Test'
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "scrutiny/base.html" %}
|
||||
{% load gadjo i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|as_template }}
|
||||
<input type="submit" value="{% trans 'Log in' %}" />
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -4,9 +4,6 @@ from django.conf.urls.static import static
|
|||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
from django.contrib.auth.views import logout_then_login
|
||||
from django.contrib.auth.urls import urlpatterns as auth_urls
|
||||
|
||||
import scrutiny.views
|
||||
from scrutiny.projects.urls import urlpatterns as projects_urls
|
||||
|
||||
|
@ -16,9 +13,12 @@ urlpatterns = [
|
|||
url(r'^$', scrutiny.views.home, name='home'),
|
||||
url(r'^projects/', include(projects_urls)),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
url(r'^accounts/logout/', logout_then_login),
|
||||
url(r'^accounts/', include(auth_urls)),
|
||||
url(r'^logout/$', scrutiny.views.logout, name='auth_logout'),
|
||||
url(r'^login/$', scrutiny.views.login, name='auth_login'),
|
||||
]
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
urlpatterns.append(url(r'^accounts/mellon/', include('mellon.urls')))
|
||||
|
|
|
@ -1,7 +1,40 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import logout as auth_logout
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import resolve_url
|
||||
from django.utils.six.moves.urllib.parse import quote
|
||||
from django.views.generic.base import TemplateView
|
||||
|
||||
from .projects.models import Project
|
||||
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
from mellon.utils import get_idps
|
||||
else:
|
||||
get_idps = lambda: []
|
||||
|
||||
|
||||
def login(request, *args, **kwargs):
|
||||
if any(get_idps()):
|
||||
if not 'next' in request.GET:
|
||||
return HttpResponseRedirect(resolve_url('mellon_login'))
|
||||
return HttpResponseRedirect(resolve_url('mellon_login') + '?next='
|
||||
+ quote(request.GET.get('next')))
|
||||
return auth_views.login(request, *args, **kwargs)
|
||||
|
||||
def logout(request, next_page=None):
|
||||
if any(get_idps()):
|
||||
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
||||
auth_logout(request)
|
||||
if next_page is not None:
|
||||
next_page = resolve_url(next_page)
|
||||
else:
|
||||
next_page = '/'
|
||||
return HttpResponseRedirect(next_page)
|
||||
|
||||
|
||||
|
||||
class Home(TemplateView):
|
||||
template_name = 'scrutiny/home.html'
|
||||
|
||||
|
|
Loading…
Reference in New Issue