Permalink
Browse files

auth: removal of django-braces mixins

  • Loading branch information...
interDist committed Jun 7, 2017
1 parent 2043f6d commit 3089f368640ad4940e72a865fe21810593e8a257
View
@@ -8,7 +8,6 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from braces.views import StaffuserRequiredMixin
from core.auth import AuthMixin, ADMIN
from hosting.models import Place
View
@@ -147,6 +147,7 @@ def get_role_in_context(request, profile=None, place=None, no_obj_context=False)
class AuthMixin(AccessMixin):
minimum_role = OWNER
allow_anonymous = False
redirect_field_name = settings.REDIRECT_FIELD_NAME
display_permission_denied = True
permission_denied_message = _("Only the supervisors of {this_country} can access this page")
@@ -3,6 +3,7 @@
def expose_selected_settings(request):
SETTINGS = [
'REDIRECT_FIELD_NAME',
'INVALID_PREFIX',
]
return {name: getattr(settings, name) for name in SETTINGS}
View
@@ -1,4 +1,6 @@
from django.contrib.auth.mixins import UserPassesTestMixin
from django.contrib.auth.mixins import LoginRequiredMixin as AuthenticatedUserRequiredMixin
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.functional import keep_lazy_text
from hosting.utils import format_lazy
@@ -35,6 +37,10 @@ def get_permission_denied_message(self):
return format_lazy(self.permission_denied_message, this_country=join_lazy(countries))
class LoginRequiredMixin(AuthenticatedUserRequiredMixin):
redirect_field_name = settings.REDIRECT_FIELD_NAME
class UserModifyMixin(object):
def get_success_url(self, *args, **kwargs):
try:
@@ -47,7 +47,7 @@
<span class="glyphicon glyphicon-log-out" title="{% trans "log out" %}"></span>
</a>
{% elif user %} {# 500/403-CSRF error pages don't have a user object #}
<a href="{% url 'login' %}?next={{ request.get_full_path|urlencode }}">
<a href="{% url 'login' %}?{{ REDIRECT_FIELD_NAME }}={{ request.get_full_path|urlencode }}">
{% trans "log in" %}
</a>
{% endif %}
@@ -60,7 +60,7 @@
<a href="{% url 'profile_create' %}">{{ user.username }}</a>
{% endif %}
{% elif user %} {# 500/403-CSRF error pages don't have a user object #}
<a href="{% url 'register' %}?next={{ request.get_full_path|urlencode }}">{% trans "register" %}</a>
<a href="{% url 'register' %}?{{ REDIRECT_FIELD_NAME }}={{ request.get_full_path|urlencode }}">{% trans "register" %}</a>
{% endif %}
</div>
</div>
@@ -29,7 +29,7 @@
<a href="{% url 'admin:index' %}">{% trans "admin site" %}</a>
{% endif %}
{% else %}
<a href="{% url 'login' %}?next={{ request.get_full_path|urlencode }}">{% trans "log in" %}</a>
<a href="{% url 'login' %}?{{ REDIRECT_FIELD_NAME }}={{ request.get_full_path|urlencode }}">{% trans "log in" %}</a>
{% endif %}
</div>
<div class="col-xs-5 col-xs-offset-1 col-sm-5 col-sm-offset-0">
@@ -40,7 +40,7 @@
<a href="{% url 'profile_create' %}">{{ user.username }}</a>
{% endif %}
{% else %}
<a href="{% url 'register' %}?next={{ request.get_full_path|urlencode }}">{% trans "register" %}</a>
<a href="{% url 'register' %}?{{ REDIRECT_FIELD_NAME }}={{ request.get_full_path|urlencode }}">{% trans "register" %}</a>
{% endif %}
</div>
</div>
@@ -7,7 +7,7 @@ <h4>{% trans "Registration" %}</h4>
<p class="tip">
{% trans "You must register to see this accomodation." %}
</p>
<form class="form row" method="POST" action="{% url 'register' %}?next={{ request.get_full_path|urlencode }}">
<form class="form row" method="POST" action="{% url 'register' %}?{{ REDIRECT_FIELD_NAME }}={{ request.get_full_path|urlencode }}">
<div class="col-sm-10 col-sm-offset-1">
{% csrf_token %}
{{ form|bootstrap }}
View
@@ -1,4 +1,5 @@
from django.conf.urls import url
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.views import (
login, logout,
@@ -24,7 +25,9 @@
url(r'^$', home, name='home'),
url(_(r'^register/$'), register, name='register'),
url(_(r'^login/$'), view=login, name='login'),
url(_(r'^login/$'), view=login, name='login',
kwargs={'redirect_authenticated_user': True,
'redirect_field_name': settings.REDIRECT_FIELD_NAME}),
url(_(r'^logout/$'), view=logout, kwargs={'next_page': '/'}, name='logout'),
url(_(r'^password/$'), view=password_change, name='password_change'),
View
@@ -2,7 +2,6 @@
from copy import copy
from markdown2 import markdown
from braces.views import AnonymousRequiredMixin, SuperuserRequiredMixin
from django.views import generic
from django.http import HttpResponseRedirect, JsonResponse, Http404
@@ -12,7 +11,6 @@
from django.contrib import messages
from django.contrib.flatpages.models import FlatPage
from django.contrib.auth import get_user_model, authenticate, login
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse_lazy
from django.db.models import Q
from django.shortcuts import get_object_or_404
@@ -28,7 +26,7 @@
from hosting.models import Place, Profile
from .auth import AuthMixin, ADMIN, SUPERVISOR, OWNER
from hosting.mixins import ProfileIsUserMixin, ProfileModifyMixin
from .mixins import SupervisorRequiredMixin, UserModifyMixin
from .mixins import LoginRequiredMixin, UserModifyMixin
from .forms import (
UsernameUpdateForm, EmailUpdateForm, EmailStaffUpdateForm,
MassMailForm, UserRegistrationForm
@@ -54,15 +52,21 @@ def right_block(self):
home = HomeView.as_view()
class RegisterView(AnonymousRequiredMixin, generic.CreateView):
class RegisterView(generic.CreateView):
model = User
template_name = 'registration/register.html'
form_class = UserRegistrationForm
success_url = reverse_lazy('profile_create')
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated:
# Only anonymous (non-authenticated) users should access the registration page.
return HttpResponseRedirect(self.get_authenticated_redirect_url())
return super().dispatch(request, *args, **kwargs)
def get_authenticated_redirect_url(self):
if self.request.GET.get('next'):
return self.request.GET['next']
if self.request.GET.get(settings.REDIRECT_FIELD_NAME):
return self.request.GET[settings.REDIRECT_FIELD_NAME]
try:
# When user is already authenticated, redirect to profile edit page.
return self.request.user.profile.get_edit_url()
View
@@ -27,9 +27,9 @@
from rest_framework import viewsets
from .serializers import ProfileSerializer, PlaceSerializer, UserSerializer
from braces.views import LoginRequiredMixin, UserPassesTestMixin, FormInvalidMessageMixin
from braces.views import FormInvalidMessageMixin
from core.auth import AuthMixin, PERM_SUPERVISOR, SUPERVISOR, OWNER, VISITOR, ANONYMOUS
from core.mixins import SupervisorRequiredMixin
from core.mixins import LoginRequiredMixin
from .mixins import (
ProfileModifyMixin, ProfileIsUserMixin,
PhoneMixin, PlaceMixin, FamilyMemberMixin, FamilyMemberAuthMixin,
@@ -138,6 +138,8 @@ def get_env_setting(setting):
LOGOUT_URL = '/'
LOGIN_REDIRECT_URL = '/'
REDIRECT_FIELD_NAME = "ps_m"
DEFAULT_FROM_EMAIL = 'Pasporta Servo <saluton@pasportaservo.org>'
CSRF_COOKIE_AGE = None
View
@@ -2,7 +2,8 @@
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin
from core.mixins import LoginRequiredMixin
from .models import Product, Reservation
from .forms import ReservationForm

0 comments on commit 3089f36

Please sign in to comment.