views.py 1.1 KB

123456789101112131415161718192021222324252627
  1. from django.contrib.auth.models import User
  2. from django.shortcuts import render_to_response, get_object_or_404
  3. from django.views.generic.detail import DetailView
  4. from coin.vpn.models import VPNSubscription
  5. class VPNView(DetailView):
  6. def get_object(self):
  7. return get_object_or_404(VPNSubscription, pk=self.args[0],
  8. administrative_subscription__member__user=self.request.user)
  9. def generate_password(request, vpn_id):
  10. """This generates a random password, saves it in hashed form, and returns
  11. it to the user in cleartext.
  12. """
  13. vpn = get_object_or_404(VPNSubscription, pk=vpn_id,
  14. administrative_subscription__member__user=request.user)
  15. # This function has nothing to here, but it's convenient.
  16. password = User.objects.make_random_password()
  17. vpn.password = password
  18. # This will hash the password automatically
  19. vpn.full_clean()
  20. vpn.save()
  21. return render_to_response('vpn/password.html', {"vpn": vpn,
  22. "password": password})