FIX: Update auth framework

This commit is contained in:
2020-02-19 14:23:28 +00:00
parent a8261e0e7e
commit 8c981cc366
13 changed files with 21 additions and 35 deletions

View File

@@ -1,3 +1,4 @@
from django.urls import path
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
@@ -15,8 +16,8 @@ urlpatterns = [
url('^assets/', include('assets.urls')),
url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail),
name="registration_register"),
url('^user/', include('django.contrib.auth.urls')),
url('^user/', include('registration.backends.default.urls')),
path('user/', include('django.contrib.auth.urls')),
path('user/', include('registration.backends.default.urls')),
url(r'^admin/', admin.site.urls),
]

View File

@@ -1,3 +1,4 @@
from django.urls import path
from django.conf.urls import url
from django.contrib.auth.views import PasswordResetView
@@ -16,8 +17,7 @@ urlpatterns = [
url('^$', login_required(views.Index.as_view()), name='index'),
url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'),
url('^user/login/$', views.login, name='login'),
url('^user/login/embed/$', xframe_options_exempt(views.login_embed), name='login_embed'),
path('user/login/embed/', xframe_options_exempt(views.LoginEmbed.as_view()), name='login_embed'),
url(r'^user/password_reset/$', PasswordResetView.as_view()),

View File

@@ -184,8 +184,7 @@ class RIGSVersion(Version):
versions = RIGSVersion.objects.get_for_object_reference(self.content_type.model_class(), thisId).select_related("revision", "revision__user").all()
try:
previousVersion = versions.filter(revision_id__lt=self.revision_id).latest(
field_name='revision__date_created')
previousVersion = versions.filter(revision_id__lt=self.revision_id).latest('revision__date_created')
except ObjectDoesNotExist:
return False

View File

@@ -3,6 +3,7 @@ from django.http.response import HttpResponseRedirect
from django.http import HttpResponse
from django.urls import reverse_lazy, reverse, NoReverseMatch
from django.views import generic
from django.contrib.auth.views import LoginView
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.core import serializers
@@ -34,28 +35,15 @@ class Index(generic.TemplateView):
return context
def login(request, **kwargs):
if request.user.is_authenticated:
next = request.GET.get('next', '/')
return HttpResponseRedirect(next)
else:
from django.contrib.auth.views import login
return login(request)
# This view should be exempt from requiring CSRF token.
# Then we can check for it and show a nice error
# Don't worry, django.contrib.auth.views.login will
# check for it before logging the user in
@csrf_exempt
def login_embed(request, **kwargs):
if request.user.is_authenticated:
next = request.GET.get('next', '/')
return HttpResponseRedirect(next)
else:
from django.contrib.auth.views import login
class LoginEmbed(LoginView):
template_name = 'registration/login_embed.html'
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
if request.method == "POST":
csrf_cookie = request.COOKIES.get('csrftoken', None)
@@ -63,7 +51,7 @@ def login_embed(request, **kwargs):
messages.warning(request, 'Cookies do not seem to be enabled. Try logging in using a new tab.')
request.method = 'GET' # Render the page without trying to login
return login(request, template_name="registration/login_embed.html", authentication_form=forms.EmbeddedAuthenticationForm)
return super().dispatch(request, *args, **kwargs)
"""

View File

@@ -19,7 +19,7 @@ icalendar==4.0.4
lxml==4.5.0
Markdown==3.2.1
Pillow==7.0.0
psycopg2==2.8.4
psycopg2-binary==2.8.4
Pygments==2.5.2
PyPDF2==1.26.0
python-dateutil==2.8.1
@@ -38,4 +38,4 @@ z3c.rml==3.9.1
zope.event==4.4
zope.interface==4.7.1
zope.schema==4.9.3
pypom==2.2.0
pypom==2.2.0

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Bad Request{% endblock %}
{% block content %}

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Unauthorized{% endblock %}
{% block content %}

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Forbidden{% endblock %}
{% block content %}

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Page Not Found{% endblock %}
{% block content %}

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Server error{% endblock %}
{% block content %}

View File

@@ -1,4 +1,4 @@
{% load static from staticfiles %}
{% load static %}
{% load raven %}
<!DOCTYPE html>

View File

@@ -1,5 +1,5 @@
{% extends 'base_rigs.html' %}
{% load staticfiles %}
{% load static %}
{% block title %}Login Required{% endblock %}
{% block js %}

View File

@@ -1,8 +1,6 @@
{% load widget_tweaks %}
{% include 'form_errors.html' %}
<div class="col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4">
<form action="{% url 'login' %}" method="post" role="form" target="_self">{% csrf_token %}
<div class="form-group">
<label for="id_username">{{ form.username.label }}</label>