views.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from django.shortcuts import render
  2. from django.http import HttpResponse
  3. from django.template import loader
  4. from django.shortcuts import redirect
  5. from django.contrib.auth import authenticate
  6. from django.views.generic.base import TemplateView
  7. from django.conf import settings
  8. from django.urls import reverse
  9. from django.contrib.auth.models import User
  10. import vyos
  11. def index(request):
  12. users_admin = User.objects.filter(
  13. is_active=True,
  14. is_superuser=True
  15. )
  16. if not request.user.is_authenticated:
  17. if users_admin.count() == 0:
  18. if 'username' in request.POST and 'password' in request.POST:
  19. user = User.objects.create_superuser(username=request.POST['username'], password=request.POST['password'])
  20. user.save()
  21. return redirect('registration-login')
  22. else:
  23. return redirect('registration-login')
  24. template = loader.get_template('registration/start.html')
  25. context = {
  26. 'users_admin': users_admin.all()
  27. }
  28. return HttpResponse(template.render(context, request))