mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-20 06:52:15 +00:00
FIX: Update auth framework
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from django.urls import path
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
@@ -15,8 +16,8 @@ urlpatterns = [
|
|||||||
url('^assets/', include('assets.urls')),
|
url('^assets/', include('assets.urls')),
|
||||||
url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail),
|
url('^user/register/$', RegistrationView.as_view(form_class=RIGS.forms.ProfileRegistrationFormUniqueEmail),
|
||||||
name="registration_register"),
|
name="registration_register"),
|
||||||
url('^user/', include('django.contrib.auth.urls')),
|
path('user/', include('django.contrib.auth.urls')),
|
||||||
url('^user/', include('registration.backends.default.urls')),
|
path('user/', include('registration.backends.default.urls')),
|
||||||
|
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from django.urls import path
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.contrib.auth.views import PasswordResetView
|
from django.contrib.auth.views import PasswordResetView
|
||||||
|
|
||||||
@@ -16,8 +17,7 @@ urlpatterns = [
|
|||||||
url('^$', login_required(views.Index.as_view()), name='index'),
|
url('^$', login_required(views.Index.as_view()), name='index'),
|
||||||
url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'),
|
url(r'^closemodal/$', views.CloseModal.as_view(), name='closemodal'),
|
||||||
|
|
||||||
url('^user/login/$', views.login, name='login'),
|
path('user/login/embed/', xframe_options_exempt(views.LoginEmbed.as_view()), name='login_embed'),
|
||||||
url('^user/login/embed/$', xframe_options_exempt(views.login_embed), name='login_embed'),
|
|
||||||
|
|
||||||
url(r'^user/password_reset/$', PasswordResetView.as_view()),
|
url(r'^user/password_reset/$', PasswordResetView.as_view()),
|
||||||
|
|
||||||
|
|||||||
@@ -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()
|
versions = RIGSVersion.objects.get_for_object_reference(self.content_type.model_class(), thisId).select_related("revision", "revision__user").all()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
previousVersion = versions.filter(revision_id__lt=self.revision_id).latest(
|
previousVersion = versions.filter(revision_id__lt=self.revision_id).latest('revision__date_created')
|
||||||
field_name='revision__date_created')
|
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from django.http.response import HttpResponseRedirect
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.urls import reverse_lazy, reverse, NoReverseMatch
|
from django.urls import reverse_lazy, reverse, NoReverseMatch
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
from django.contrib.auth.views import LoginView
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
@@ -34,28 +35,15 @@ class Index(generic.TemplateView):
|
|||||||
return context
|
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.
|
# This view should be exempt from requiring CSRF token.
|
||||||
# Then we can check for it and show a nice error
|
# Then we can check for it and show a nice error
|
||||||
# Don't worry, django.contrib.auth.views.login will
|
# Don't worry, django.contrib.auth.views.login will
|
||||||
# check for it before logging the user in
|
# check for it before logging the user in
|
||||||
@csrf_exempt
|
class LoginEmbed(LoginView):
|
||||||
def login_embed(request, **kwargs):
|
template_name = 'registration/login_embed.html'
|
||||||
if request.user.is_authenticated:
|
|
||||||
next = request.GET.get('next', '/')
|
|
||||||
return HttpResponseRedirect(next)
|
|
||||||
else:
|
|
||||||
from django.contrib.auth.views import login
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
csrf_cookie = request.COOKIES.get('csrftoken', None)
|
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.')
|
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
|
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)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ icalendar==4.0.4
|
|||||||
lxml==4.5.0
|
lxml==4.5.0
|
||||||
Markdown==3.2.1
|
Markdown==3.2.1
|
||||||
Pillow==7.0.0
|
Pillow==7.0.0
|
||||||
psycopg2==2.8.4
|
psycopg2-binary==2.8.4
|
||||||
Pygments==2.5.2
|
Pygments==2.5.2
|
||||||
PyPDF2==1.26.0
|
PyPDF2==1.26.0
|
||||||
python-dateutil==2.8.1
|
python-dateutil==2.8.1
|
||||||
@@ -38,4 +38,4 @@ z3c.rml==3.9.1
|
|||||||
zope.event==4.4
|
zope.event==4.4
|
||||||
zope.interface==4.7.1
|
zope.interface==4.7.1
|
||||||
zope.schema==4.9.3
|
zope.schema==4.9.3
|
||||||
pypom==2.2.0
|
pypom==2.2.0
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Bad Request{% endblock %}
|
{% block title %}Bad Request{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Unauthorized{% endblock %}
|
{% block title %}Unauthorized{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Forbidden{% endblock %}
|
{% block title %}Forbidden{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Page Not Found{% endblock %}
|
{% block title %}Page Not Found{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Server error{% endblock %}
|
{% block title %}Server error{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{% load static from staticfiles %}
|
{% load static %}
|
||||||
{% load raven %}
|
{% load raven %}
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% extends 'base_rigs.html' %}
|
{% extends 'base_rigs.html' %}
|
||||||
{% load staticfiles %}
|
{% load static %}
|
||||||
{% block title %}Login Required{% endblock %}
|
{% block title %}Login Required{% endblock %}
|
||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
{% load widget_tweaks %}
|
{% load widget_tweaks %}
|
||||||
{% include 'form_errors.html' %}
|
{% include 'form_errors.html' %}
|
||||||
<div class="col-sm-6 col-sm-offset-3 col-lg-4 col-lg-offset-4">
|
<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 %}
|
<form action="{% url 'login' %}" method="post" role="form" target="_self">{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="id_username">{{ form.username.label }}</label>
|
<label for="id_username">{{ form.username.label }}</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user