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

request.user.is_authenticated() substitued for @login_required decorator

settings.LOGIN_URL = /accounts/login
This commit is contained in:
Jan Krcmar 2015-12-22 15:09:02 +01:00
parent ae4fdcec92
commit dac974ddab
10 changed files with 33 additions and 61 deletions

View file

@ -3,18 +3,18 @@ from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required
from accounts.models import UserInstance, UserSSHKey
from instances.models import Instance
from accounts.forms import UserAddForm
@login_required
def profile(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
error_messages = []
user = User.objects.get(id=request.user.id)
@ -63,16 +63,13 @@ def profile(request):
return HttpResponseRedirect(request.get_full_path())
return render(request, 'profile.html', locals())
@login_required
def accounts(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -123,15 +120,13 @@ def accounts(request):
return render(request, 'accounts.html', locals())
@login_required
def account(request, user_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -3,6 +3,7 @@ import json
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from instances.models import Instance
from accounts.models import UserInstance
@ -12,15 +13,13 @@ from vrtManager.connection import CONN_SSH, CONN_TCP, CONN_TLS, CONN_SOCKET, con
from libvirt import libvirtError
@login_required
def computes(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -130,15 +129,13 @@ def computes(request):
return render(request, 'computes.html', locals())
@login_required
def overview(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -160,15 +157,13 @@ def overview(request, compute_id):
return render(request, 'overview.html', locals())
@login_required
def compute_graph(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
points = 5
datasets = {}
cookies = {}

View file

@ -2,6 +2,7 @@ import re
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from instances.models import Instance
from vrtManager.instance import wvmInstance
from webvirtcloud.settings import WS_PORT
@ -9,15 +10,13 @@ from webvirtcloud.settings import WS_PUBLIC_HOST
from libvirt import libvirtError
@login_required
def console(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
if request.method == 'GET':
token = request.GET.get('token', '')

View file

@ -2,6 +2,7 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from create.models import Flavor
from create.forms import FlavorAddForm, NewVMForm
@ -11,15 +12,13 @@ from vrtManager import util
from libvirt import libvirtError
@login_required
def create_instance(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -9,6 +9,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from instances.models import Instance
from accounts.models import UserInstance, UserSSHKey
@ -20,27 +21,23 @@ from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES
from logs.views import addlogmsg
@login_required
def index(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
else:
return HttpResponseRedirect(reverse('instances'))
return HttpResponseRedirect(reverse('instances'))
@login_required
def instances(request):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
error_messages = []
all_host_vms = {}
all_user_vms = {}
@ -144,15 +141,13 @@ def instances(request):
return render(request, 'instances.html', locals())
@login_required
def instance(request, compute_id, vname):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
error_messages = []
messages = []
compute = get_object_or_404(Compute, pk=compute_id)
@ -517,15 +512,13 @@ def instance(request, compute_id, vname):
return render(request, 'instance.html', locals())
@login_required
def inst_status(request, compute_id, vname):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
compute = get_object_or_404(Compute, pk=compute_id)
response = HttpResponse()
response['Content-Type'] = "text/javascript"
@ -544,15 +537,13 @@ def inst_status(request, compute_id, vname):
return response
@login_required
def inst_graph(request, compute_id, vname):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('login'))
datasets = {}
json_blk = []
datasets_blk = {}

View file

@ -1,21 +1,20 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from interfaces.forms import AddInterface
from vrtManager.interface import wvmInterface, wvmInterfaces
from libvirt import libvirtError
@login_required
def interfaces(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -57,15 +56,13 @@ def interfaces(request, compute_id):
return render(request, 'interfaces.html', locals())
@login_required
def interface(request, compute_id, iface):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -2,6 +2,7 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from networks.forms import AddNetPool
from vrtManager.network import wvmNetwork, wvmNetworks
@ -9,15 +10,13 @@ from vrtManager.network import network_size
from libvirt import libvirtError
@login_required
def networks(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -60,15 +59,13 @@ def networks(request, compute_id):
return render(request, 'networks.html', locals())
@login_required
def network(request, compute_id, pool):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -1,21 +1,20 @@
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from secrets.forms import AddSecret
from vrtManager.secrets import wvmSecrets
from libvirt import libvirtError
@login_required
def secrets(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -2,21 +2,20 @@ from django.shortcuts import render, get_object_or_404
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from computes.models import Compute
from storages.forms import AddStgPool, AddImage, CloneImage
from vrtManager.storage import wvmStorage, wvmStorages
from libvirt import libvirtError
@login_required
def storages(request, compute_id):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))
@ -68,15 +67,13 @@ def storages(request, compute_id):
return render(request, 'storages.html', locals())
@login_required
def storage(request, compute_id, pool):
"""
:param request:
:return:
"""
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
if not request.user.is_superuser:
return HttpResponseRedirect(reverse('index'))

View file

@ -46,8 +46,11 @@ MIDDLEWARE_CLASSES = (
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.RemoteUserBackend',
#'accounts.backends.MyRemoteUserBackend',
)
LOGIN_URL = '/accounts/login'
ROOT_URLCONF = 'webvirtcloud.urls'
WSGI_APPLICATION = 'webvirtcloud.wsgi.application'