2018-01-02 17:06:12 +01:00
|
|
|
import django
|
2017-09-16 02:33:40 +02:00
|
|
|
from django.views.generic import RedirectView
|
2018-05-10 11:42:52 +02:00
|
|
|
from django.contrib import admin
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
2017-08-03 12:40:52 +02:00
|
|
|
|
2018-01-02 17:06:12 +01:00
|
|
|
if django.VERSION >= (1, 10):
|
|
|
|
from django.urls import reverse_lazy
|
|
|
|
else:
|
|
|
|
from django.core.urlresolvers import reverse_lazy
|
|
|
|
|
2017-08-03 12:40:52 +02:00
|
|
|
|
2017-09-16 02:33:40 +02:00
|
|
|
class CaptureLogin(RedirectView):
|
|
|
|
url = reverse_lazy('account_login')
|
|
|
|
query_string = True
|
2018-01-02 17:06:12 +01:00
|
|
|
permanent = False
|
2017-08-03 12:40:52 +02:00
|
|
|
|
|
|
|
|
2017-09-16 02:33:40 +02:00
|
|
|
capture_login = CaptureLogin.as_view()
|
|
|
|
|
|
|
|
|
|
|
|
class CaptureLogout(RedirectView):
|
|
|
|
url = reverse_lazy('account_logout')
|
|
|
|
query_string = True
|
2018-01-02 17:06:12 +01:00
|
|
|
permanent = False
|
2017-09-16 02:33:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
capture_logout = CaptureLogout.as_view()
|
2018-05-10 11:42:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
def capture_login_admin(request):
|
|
|
|
""" Redirect the user to allauth login page if they are not logged in, or
|
|
|
|
fails and display a message if they are logged in *but* are not
|
|
|
|
administrators """
|
|
|
|
|
|
|
|
if admin.site.has_permission(request):
|
|
|
|
return capture_login(request)
|
|
|
|
|
|
|
|
context = {
|
|
|
|
'message': ("The account you're authenticated with is not an "
|
|
|
|
"administrator account."),
|
|
|
|
}
|
|
|
|
return render(request,
|
|
|
|
"allauth_ens/simple_message.html",
|
|
|
|
context=context)
|