No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # This file is part of dnmgmt, a number resource management system
  2. # Licensed under GNU General Public License v3 or later
  3. # Written by Sebastian Lohff (seba@someserver.de)
  4. from django.shortcuts import render
  5. from django.contrib.auth.decorators import login_required
  6. from django.contrib.auth.forms import PasswordChangeForm
  7. from django.contrib.auth import login as auth_login
  8. from django.db.models import Q
  9. from django.views.generic import CreateView
  10. from django.urls import reverse_lazy, reverse
  11. from django.contrib import messages
  12. from django.http import HttpResponseRedirect
  13. from whoisdb.models import ASNumber, InetNum
  14. from domains.models import Domain
  15. from rrequests.models import Request
  16. from .forms import CustomUserCreationForm
  17. @login_required
  18. def profile(request):
  19. pwForm = None
  20. if request.method == "POST":
  21. if request.POST.get("submit", None) == "pwchange":
  22. pwForm = PasswordChangeForm(user=request.user, data=request.POST)
  23. if pwForm.is_valid():
  24. pwForm.save()
  25. auth_login(request, pwForm.user)
  26. messages.success(request, "Password changed")
  27. return HttpResponseRedirect(reverse("user:profile"))
  28. if not pwForm:
  29. pwForm = PasswordChangeForm(user=request.user)
  30. return render(request, "registration/profile.html", {'pwForm': pwForm})
  31. @login_required
  32. def dashboard(request):
  33. mnts = request.user.maintainer_set.all()
  34. ownMnts = request.user.maintainer_set.filter(rir=False, lir=False).all().distinct()
  35. # if account only has rir/lir objects, show them
  36. if ownMnts.count() == 0:
  37. ownMnts = mnts
  38. asns = ASNumber.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
  39. inetnums = InetNum.objects.filter(Q(mnt_by__in=ownMnts) | Q(mnt_lower__in=ownMnts)).distinct()
  40. domains = Domain.objects.filter(mnt_by__in=mnts).distinct()
  41. rrequests = Request.objects.filter((Q(provider__in=mnts) | Q(applicant__in=mnts)) & Q(status=Request.STATE_OPEN)).distinct()
  42. return render(request, "dncore/dashboard.html", {"asns": asns, "inetnums": inetnums, "domains": domains, 'rrequests': rrequests})
  43. def index(request):
  44. if request.user.is_authenticated():
  45. return HttpResponseRedirect(reverse("dashboard"))
  46. return render(request, "index.html", {})
  47. class RegisterUser(CreateView):
  48. template_name = "dncore/registration.html"
  49. form_class = CustomUserCreationForm
  50. success_url = reverse_lazy("user:login")
  51. def form_valid(self, form):
  52. ret = super(RegisterUser, self).form_valid(form)
  53. messages.success(self.request, "You successfully registered as user %s and can now log in!" % form.instance.username)
  54. return ret