mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Removed django-braces requirement.
This commit is contained in:
@@ -9,10 +9,10 @@ from django.contrib.auth import (
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
|
||||
from braces.forms import UserKwargModelFormMixin
|
||||
import django_otp
|
||||
|
||||
from modoboa.core.models import User
|
||||
from modoboa.lib.form_utils import UserKwargModelFormMixin
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import logging
|
||||
|
||||
import oath
|
||||
|
||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||
from django.http import (
|
||||
HttpResponse, HttpResponseRedirect, Http404, JsonResponse)
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
@@ -17,15 +18,15 @@ from django.views.decorators.cache import never_cache
|
||||
from django.contrib.auth import (
|
||||
authenticate, login, logout, views as auth_views
|
||||
)
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
|
||||
from braces.views import (
|
||||
JSONResponseMixin, LoginRequiredMixin, UserFormKwargsMixin)
|
||||
import django_otp
|
||||
|
||||
from modoboa.core import forms
|
||||
from modoboa.core.password_hashers import get_password_hasher
|
||||
from modoboa.lib import cryptutils
|
||||
from modoboa.lib.views import UserFormKwargsMixin
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
from .. import models
|
||||
@@ -204,7 +205,7 @@ class VerifySMSCodeView(generic.FormView):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
class ResendSMSCodeView(JSONResponseMixin, generic.View):
|
||||
class ResendSMSCodeView(generic.View):
|
||||
"""A view to resend validation code."""
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
@@ -230,7 +231,7 @@ class ResendSMSCodeView(JSONResponseMixin, generic.View):
|
||||
if not backend.send(text, [user.phone_number]):
|
||||
raise Http404
|
||||
self.request.session["totp_secret"] = secret
|
||||
return self.render_json_response({"status": "ok"})
|
||||
return JsonResponse({"status": "ok"})
|
||||
|
||||
|
||||
class TwoFactorCodeVerifyView(LoginRequiredMixin,
|
||||
|
||||
@@ -360,6 +360,14 @@ class TabForms(object):
|
||||
context["tabs"].active_id = active_tab_id
|
||||
return render(self.request, self.template_name, context)
|
||||
|
||||
|
||||
class UserKwargModelFormMixin:
|
||||
"""Simple form mixin to add support for user kwargs in constructor."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop("user")
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
#
|
||||
# Custom fields from here
|
||||
#
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
"""Views utilities."""
|
||||
|
||||
|
||||
class UserFormKwargsMixin:
|
||||
"""A mixin to automatically add a user arg to form instantiation."""
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
@@ -1,5 +1,4 @@
|
||||
django>=2.2,<2.3
|
||||
django-braces==1.14.0
|
||||
django-ckeditor==6.0.0
|
||||
django-phonenumber-field[phonenumbers]==5.0.0
|
||||
django-reversion==3.0.9
|
||||
|
||||
Reference in New Issue
Block a user