1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

Added django-login-required-middleware

Thus eliminating need for login_requred decorator on every view
This commit is contained in:
Real-Gecko 2020-05-27 12:43:29 +06:00
parent 6d82c2820b
commit 38befa4362
14 changed files with 12 additions and 54 deletions

View file

@ -15,9 +15,9 @@
{% endif %} {% endif %}
<form class="form-signin" method="post" role="form">{% csrf_token %} <form class="form-signin" method="post" role="form">{% csrf_token %}
<h2 class="form-signin-heading">{% trans "Sign In" %}</h2> <h2 class="form-signin-heading">{% trans "Sign In" %}</h2>
<input type="text" class="form-control" name="username" placeholder="Login" autocapitalize="none" autocorrect="off" autofocus> <input type="text" class="form-control" name="username" placeholder="{% trans "Login" %}" autocapitalize="none" autocorrect="off" autofocus>
<input type="password" class="form-control" name="password" placeholder="Password"> <input type="password" class="form-control" name="password" placeholder="{% trans "Password" %}">
<input name="next" id="next" type="hidden" value="{% url 'allinstances' %}"> <input type="hidden" name="next" value="{{ next }}">
<button class="btn btn-lg btn-success btn-block" type="submit">{% trans "Sign In" %}</button> <button class="btn btn-lg btn-success btn-block" type="submit">{% trans "Sign In" %}</button>
</form> </form>
</div> </div>

View file

@ -2,7 +2,6 @@ from django.shortcuts import render
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.decorators import login_required
from accounts.models import * from accounts.models import *
from instances.models import Instance from instances.models import Instance
from accounts.forms import UserAddForm from accounts.forms import UserAddForm
@ -10,7 +9,6 @@ from django.conf import settings
from django.core.validators import ValidationError from django.core.validators import ValidationError
@login_required
def profile(request): def profile(request):
""" """
:param request: :param request:
@ -69,7 +67,6 @@ def profile(request):
return render(request, 'profile.html', locals()) return render(request, 'profile.html', locals())
@login_required
def accounts(request): def accounts(request):
""" """
:param request: :param request:
@ -149,7 +146,6 @@ def accounts(request):
return render(request, accounts_template_file, locals()) return render(request, accounts_template_file, locals())
@login_required
def account(request, user_id): def account(request, user_id):
""" """
:param request: :param request:

View file

@ -3,7 +3,6 @@ from django.utils import timezone
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from instances.models import Instance from instances.models import Instance
from accounts.models import UserInstance from accounts.models import UserInstance
@ -13,7 +12,6 @@ from vrtManager.connection import CONN_SSH, CONN_TCP, CONN_TLS, CONN_SOCKET, con
from libvirt import libvirtError from libvirt import libvirtError
@login_required
def computes(request): def computes(request):
""" """
:param request: :param request:
@ -135,7 +133,6 @@ def computes(request):
return render(request, 'computes.html', locals()) return render(request, 'computes.html', locals())
@login_required
def overview(request, compute_id): def overview(request, compute_id):
""" """
:param request: :param request:
@ -167,7 +164,6 @@ def overview(request, compute_id):
return render(request, 'overview.html', locals()) return render(request, 'overview.html', locals())
@login_required
def compute_graph(request, compute_id): def compute_graph(request, compute_id):
""" """
:param request: :param request:
@ -197,7 +193,6 @@ def compute_graph(request, compute_id):
return response return response
@login_required
def get_compute_disk_buses(request, compute_id, arch, machine, disk): def get_compute_disk_buses(request, compute_id, arch, machine, disk):
data = dict() data = dict()
compute = get_object_or_404(Compute, pk=compute_id) compute = get_object_or_404(Compute, pk=compute_id)
@ -224,7 +219,6 @@ def get_compute_disk_buses(request, compute_id, arch, machine, disk):
return HttpResponse(json.dumps(data)) return HttpResponse(json.dumps(data))
@login_required
def get_compute_machine_types(request, compute_id, arch): def get_compute_machine_types(request, compute_id, arch):
data = dict() data = dict()
try: try:
@ -240,7 +234,6 @@ def get_compute_machine_types(request, compute_id, arch):
return HttpResponse(json.dumps(data)) return HttpResponse(json.dumps(data))
@login_required
def get_compute_video_models(request, compute_id, arch, machine): def get_compute_video_models(request, compute_id, arch, machine):
data = dict() data = dict()
try: try:
@ -256,7 +249,6 @@ def get_compute_video_models(request, compute_id, arch, machine):
return HttpResponse(json.dumps(data)) return HttpResponse(json.dumps(data))
@login_required
def get_dom_capabilities(request, compute_id, arch, machine): def get_dom_capabilities(request, compute_id, arch, machine):
data = dict() data = dict()
try: try:

View file

@ -1,8 +1,11 @@
Django==2.2.12 Django==2.2.12
websockify==0.9.0 django-login-required-middleware==0.5.0
gunicorn==20.0.4 gunicorn==20.0.4
lxml==4.5.0
libvirt-python==6.1.0 libvirt-python==6.1.0
six lxml==4.5.0
pytz numpy==1.18.4
rwlock pytz==2020.1
rwlock==0.0.7
six==1.15.0
sqlparse==0.3.1
websockify==0.9.0

View file

@ -1,6 +1,5 @@
import re import re
from django.shortcuts import render from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from instances.models import Instance from instances.models import Instance
from vrtManager.instance import wvmInstance from vrtManager.instance import wvmInstance
from webvirtcloud.settings import WS_PUBLIC_PORT from webvirtcloud.settings import WS_PUBLIC_PORT
@ -8,7 +7,6 @@ from webvirtcloud.settings import WS_PUBLIC_HOST
from libvirt import libvirtError from libvirt import libvirtError
@login_required
def console(request): def console(request):
""" """
:param request: :param request:

View file

@ -2,7 +2,6 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from create.models import Flavor from create.models import Flavor
from create.forms import FlavorAddForm, NewVMForm from create.forms import FlavorAddForm, NewVMForm
@ -26,7 +25,6 @@ from django.contrib import messages
from logs.views import addlogmsg from logs.views import addlogmsg
@login_required
def create_instance_select_type(request, compute_id): def create_instance_select_type(request, compute_id):
if not request.user.is_superuser: if not request.user.is_superuser:
@ -76,7 +74,6 @@ def create_instance_select_type(request, compute_id):
return render(request, 'create_instance_w1.html', locals()) return render(request, 'create_instance_w1.html', locals())
@login_required
def create_instance(request, compute_id, arch, machine): def create_instance(request, compute_id, arch, machine):
""" """
:param request: :param request:

View file

@ -11,7 +11,6 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from instances.models import Instance from instances.models import Instance
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -29,7 +28,6 @@ from django.contrib import messages
from collections import OrderedDict from collections import OrderedDict
@login_required
def index(request): def index(request):
""" """
:param request: :param request:
@ -38,7 +36,6 @@ def index(request):
return HttpResponseRedirect(reverse('allinstances')) return HttpResponseRedirect(reverse('allinstances'))
@login_required
def allinstances(request): def allinstances(request):
""" """
INSTANCES LIST FOR ALL HOSTS INSTANCES LIST FOR ALL HOSTS
@ -70,7 +67,6 @@ def allinstances(request):
return render(request, 'allinstances.html', locals()) return render(request, 'allinstances.html', locals())
@login_required
def instances(request, compute_id): def instances(request, compute_id):
""" """
:param request: :param request:
@ -99,7 +95,6 @@ def instances(request, compute_id):
return render(request, 'instances.html', locals()) return render(request, 'instances.html', locals())
@login_required
def instance(request, compute_id, vname): def instance(request, compute_id, vname):
""" """
:param request: :param request:
@ -1081,7 +1076,6 @@ def instance(request, compute_id, vname):
return render(request, 'instance.html', locals()) return render(request, 'instance.html', locals())
@login_required
def inst_status(request, compute_id, vname): def inst_status(request, compute_id, vname):
""" """
:param request: :param request:
@ -1276,7 +1270,6 @@ def instances_actions(request):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
@login_required
def inst_graph(request, compute_id, vname): def inst_graph(request, compute_id, vname):
""" """
:param request: :param request:
@ -1339,7 +1332,6 @@ def _get_dhcp_mac_address(vname):
return mac return mac
@login_required
def guess_mac_address(request, vname): def guess_mac_address(request, vname):
data = {'vname': vname} data = {'vname': vname}
mac = _get_dhcp_mac_address(vname) mac = _get_dhcp_mac_address(vname)
@ -1358,14 +1350,12 @@ def _get_random_mac_address():
return mac return mac
@login_required
def random_mac_address(request): def random_mac_address(request):
data = dict() data = dict()
data['mac'] = _get_random_mac_address() data['mac'] = _get_random_mac_address()
return HttpResponse(json.dumps(data)) return HttpResponse(json.dumps(data))
@login_required
def guess_clone_name(request): def guess_clone_name(request):
dhcp_file = '/srv/webvirtcloud/dhcpd.conf' dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX prefix = settings.CLONE_INSTANCE_DEFAULT_PREFIX
@ -1382,7 +1372,6 @@ def guess_clone_name(request):
return HttpResponse(json.dumps({})) return HttpResponse(json.dumps({}))
@login_required
def check_instance(request, vname): def check_instance(request, vname):
instance = Instance.objects.filter(name=vname) instance = Instance.objects.filter(name=vname)
data = {'vname': vname, 'exists': False} data = {'vname': vname, 'exists': False}

View file

@ -1,14 +1,12 @@
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from interfaces.forms import AddInterface from interfaces.forms import AddInterface
from vrtManager.interface import wvmInterface, wvmInterfaces from vrtManager.interface import wvmInterface, wvmInterfaces
from libvirt import libvirtError from libvirt import libvirtError
@login_required
def interfaces(request, compute_id): def interfaces(request, compute_id):
""" """
:param request: :param request:
@ -57,7 +55,6 @@ def interfaces(request, compute_id):
return render(request, 'interfaces.html', locals()) return render(request, 'interfaces.html', locals())
@login_required
def interface(request, compute_id, iface): def interface(request, compute_id, iface):
""" """
:param request: :param request:

View file

@ -1,7 +1,6 @@
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from instances.models import Instance from instances.models import Instance
from logs.models import Logs from logs.models import Logs
from django.conf import settings from django.conf import settings
@ -19,7 +18,6 @@ def addlogmsg(user, instance, message):
add_log_msg.save() add_log_msg.save()
@login_required
def showlogs(request, page=1): def showlogs(request, page=1):
""" """
:param request: :param request:
@ -40,7 +38,6 @@ def showlogs(request, page=1):
return render(request, 'showlogs.html', locals()) return render(request, 'showlogs.html', locals())
@login_required
def vm_logs(request, vname): def vm_logs(request, vname):
""" """
:param request: :param request:

View file

@ -2,7 +2,6 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from networks.forms import AddNetPool from networks.forms import AddNetPool
from vrtManager.network import wvmNetwork, wvmNetworks from vrtManager.network import wvmNetwork, wvmNetworks
@ -11,7 +10,6 @@ from libvirt import libvirtError
from django.contrib import messages from django.contrib import messages
@login_required
def networks(request, compute_id): def networks(request, compute_id):
""" """
:param request: :param request:
@ -70,7 +68,6 @@ def networks(request, compute_id):
return render(request, 'networks.html', locals()) return render(request, 'networks.html', locals())
@login_required
def network(request, compute_id, pool): def network(request, compute_id, pool):
""" """
:param request: :param request:

View file

@ -5,7 +5,6 @@ from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from vrtManager import util from vrtManager import util
from vrtManager.nwfilters import wvmNWFilters, wvmNWFilter from vrtManager.nwfilters import wvmNWFilters, wvmNWFilter
@ -14,7 +13,6 @@ from libvirt import libvirtError
from logs.views import addlogmsg from logs.views import addlogmsg
@login_required
def nwfilters(request, compute_id): def nwfilters(request, compute_id):
""" """
:param request: :param request:
@ -112,7 +110,6 @@ def nwfilters(request, compute_id):
'compute': compute}) 'compute': compute})
@login_required
def nwfilter(request, compute_id, nwfltr): def nwfilter(request, compute_id, nwfltr):
error_messages = [] error_messages = []

View file

@ -1,14 +1,12 @@
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from secrets.forms import AddSecret from secrets.forms import AddSecret
from vrtManager.secrets import wvmSecrets from vrtManager.secrets import wvmSecrets
from libvirt import libvirtError from libvirt import libvirtError
@login_required
def secrets(request, compute_id): def secrets(request, compute_id):
""" """
:param request: :param request:

View file

@ -2,7 +2,6 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse from django.http import HttpResponseRedirect, HttpResponse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute from computes.models import Compute
from storages.forms import AddStgPool, AddImage, CloneImage from storages.forms import AddStgPool, AddImage, CloneImage
from vrtManager.storage import wvmStorage, wvmStorages from vrtManager.storage import wvmStorage, wvmStorages
@ -11,7 +10,6 @@ from django.contrib import messages
import json import json
@login_required
def storages(request, compute_id): def storages(request, compute_id):
""" """
:param request: :param request:
@ -70,7 +68,6 @@ def storages(request, compute_id):
return render(request, 'storages.html', locals()) return render(request, 'storages.html', locals())
@login_required
def storage(request, compute_id, pool): def storage(request, compute_id, pool):
""" """
:param request: :param request:
@ -215,7 +212,6 @@ def storage(request, compute_id, pool):
return render(request, 'storage.html', locals()) return render(request, 'storage.html', locals())
@login_required
def get_volumes(request, compute_id, pool): def get_volumes(request, compute_id, pool):
data = {} data = {}
compute = get_object_or_404(Compute, pk=compute_id) compute = get_object_or_404(Compute, pk=compute_id)

View file

@ -44,6 +44,7 @@ MIDDLEWARE = [
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'login_required.middleware.LoginRequiredMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware', 'django.contrib.auth.middleware.RemoteUserMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',