2017-02-10 02:45:45 +01:00
|
|
|
from django.shortcuts import render
|
2017-02-14 22:26:16 +01:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2017-03-28 01:43:24 +02:00
|
|
|
from django.contrib.auth.forms import PasswordChangeForm
|
|
|
|
from django.contrib.auth import login as auth_login
|
2017-03-15 03:07:43 +01:00
|
|
|
from django.db.models import Q
|
2017-03-22 04:06:24 +01:00
|
|
|
from django.views.generic import CreateView
|
2017-03-22 19:11:19 +01:00
|
|
|
from django.urls import reverse_lazy, reverse
|
2017-03-22 04:06:24 +01:00
|
|
|
from django.contrib import messages
|
2017-03-22 19:11:19 +01:00
|
|
|
from django.http import HttpResponseRedirect
|
2017-03-22 04:06:24 +01:00
|
|
|
|
2017-03-15 03:07:43 +01:00
|
|
|
|
|
|
|
from whoisdb.models import ASNumber, InetNum
|
|
|
|
from domains.models import Domain
|
|
|
|
from rrequests.models import Request
|
|
|
|
|
2017-03-22 04:06:24 +01:00
|
|
|
from .forms import CustomUserCreationForm
|
|
|
|
|
2017-02-10 02:45:45 +01:00
|
|
|
|
2017-02-14 22:26:16 +01:00
|
|
|
@login_required
|
|
|
|
def profile(request):
|
2017-03-28 01:43:24 +02:00
|
|
|
pwForm = None
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
if request.POST.get("submit", None) == "pwchange":
|
|
|
|
pwForm = PasswordChangeForm(user=request.user, data=request.POST)
|
|
|
|
if pwForm.is_valid():
|
|
|
|
pwForm.save()
|
|
|
|
auth_login(request, pwForm.user)
|
|
|
|
messages.success(request, "Password changed")
|
|
|
|
|
2017-04-15 16:51:07 +02:00
|
|
|
return HttpResponseRedirect(reverse("user:profile"))
|
2017-03-28 01:43:24 +02:00
|
|
|
|
|
|
|
if not pwForm:
|
|
|
|
pwForm = PasswordChangeForm(user=request.user)
|
|
|
|
|
|
|
|
return render(request, "registration/profile.html", {'pwForm': pwForm})
|
2017-02-14 22:26:16 +01:00
|
|
|
|
2017-03-15 03:07:43 +01:00
|
|
|
|
2017-02-14 22:26:16 +01:00
|
|
|
@login_required
|
|
|
|
def dashboard(request):
|
2017-03-15 03:07:43 +01:00
|
|
|
mnts = request.user.maintainer_set.all()
|
2017-03-28 01:43:24 +02:00
|
|
|
ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all().distinct()
|
2017-10-12 21:28:42 +02:00
|
|
|
# if account only has rir/lir objects, show them
|
|
|
|
if ownMnts.count() == 0:
|
|
|
|
ownMnts = mnts
|
|
|
|
|
2017-03-28 01:43:24 +02:00
|
|
|
asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
|
|
|
|
inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
|
|
|
|
domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
|
|
|
|
rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN)).distinct()
|
2017-03-15 03:07:43 +01:00
|
|
|
|
|
|
|
return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests})
|
|
|
|
|
2017-02-14 22:26:16 +01:00
|
|
|
|
|
|
|
def index(request):
|
2017-03-22 19:11:19 +01:00
|
|
|
if request.user.is_authenticated():
|
|
|
|
return HttpResponseRedirect(reverse("dashboard"))
|
|
|
|
|
2017-02-14 22:26:16 +01:00
|
|
|
return render(request, "index.html", {})
|
2017-03-22 04:06:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RegisterUser(CreateView):
|
|
|
|
template_name = "dncore/registration.html"
|
|
|
|
form_class = CustomUserCreationForm
|
|
|
|
success_url = reverse_lazy("user:login")
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
ret = super(RegisterUser, self).form_valid(form)
|
|
|
|
messages.success(self.request, "You successfully registered as user %s and can now log in!" % form.instance.username)
|
|
|
|
|
|
|
|
return ret
|