views.py 889 B

1234567891011121314151617181920212223242526272829303132
  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. import vyos
  7. def index(request):
  8. all_instances = vyos.instance_getall()
  9. hostname_default = vyos.get_hostname_prefered(request)
  10. if 'username' in request.POST and 'password' in request.POST:
  11. user = authenticate(username=request.POST['username'], password=request.POST['password'])
  12. if user is not None:
  13. # A backend authenticated the credentials
  14. return redirect('firewall:firewall-list')
  15. else:
  16. pass
  17. template = loader.get_template('vauth/login.html')
  18. context = {
  19. 'instances': all_instances,
  20. 'hostname_default': hostname_default,
  21. }
  22. return HttpResponse(template.render(context, request))