misc: update login/logout to be class based views (#36331)
This commit is contained in:
parent
7810f16265
commit
fe7f3482c8
|
@ -145,6 +145,7 @@ if mellon is not None:
|
|||
LOGIN_URL = '/login/'
|
||||
LOGIN_REDIRECT_URL = '/'
|
||||
LOGOUT_URL = '/logout/'
|
||||
LOGOUT_REDIRECT_URL = '/'
|
||||
|
||||
MELLON_ATTRIBUTE_MAPPING = {
|
||||
'email': '{attributes[email][0]}',
|
||||
|
|
|
@ -21,7 +21,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
|||
|
||||
from .urls_utils import decorated_includes, manager_required
|
||||
|
||||
from .views import homepage, login, logout
|
||||
from .views import homepage, LoginView, LogoutView
|
||||
from .api.urls import urlpatterns as chrono_api_urls
|
||||
from .manager.urls import urlpatterns as chrono_manager_urls
|
||||
|
||||
|
@ -31,8 +31,8 @@ urlpatterns = [
|
|||
url(r'^manage/', decorated_includes(manager_required,
|
||||
include(chrono_manager_urls))),
|
||||
url(r'^api/', include(chrono_api_urls)),
|
||||
url(r'^logout/$', logout, name='auth_logout'),
|
||||
url(r'^login/$', login, name='auth_login'),
|
||||
url(r'^logout/$', LogoutView.as_view(), name='auth_logout'),
|
||||
url(r'^login/$', LoginView.as_view(), name='auth_login'),
|
||||
]
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.decorators import method_decorator
|
||||
from django.utils.six.moves.urllib.parse import quote
|
||||
from django.views.decorators.cache import never_cache
|
||||
|
||||
|
||||
if 'mellon' in settings.INSTALLED_APPS:
|
||||
from mellon.utils import get_idps
|
||||
|
@ -28,28 +30,22 @@ else:
|
|||
|
||||
|
||||
class LoginView(auth_views.LoginView):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
def get(self, request, *args, **kwargs):
|
||||
if any(get_idps()):
|
||||
if 'next' not in request.GET:
|
||||
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 super(LoginView, self).dispatch(request, *args, **kwargs)
|
||||
pass
|
||||
return super(LoginView, self).get(request, *args, **kwargs)
|
||||
|
||||
|
||||
login = LoginView.as_view()
|
||||
class LogoutView(auth_views.LogoutView):
|
||||
@method_decorator(never_cache)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
if any(get_idps()):
|
||||
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
||||
return super(LogoutView, self).dispatch(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)
|
||||
|
||||
def homepage(request, *args, **kwargs):
|
||||
return HttpResponseRedirect(resolve_url('chrono-manager-homepage'))
|
||||
|
|
Loading…
Reference in New Issue