|
@@ -1,3 +1,19 @@
|
|
|
-from django.shortcuts import render
|
|
|
+from django.contrib.auth.models import User
|
|
|
+from django.shortcuts import render_to_response, get_object_or_404
|
|
|
|
|
|
-# Create your views here.
|
|
|
+from coin.vpn.models import VPNSubscription
|
|
|
+
|
|
|
+def generate_password(request, vpn_id):
|
|
|
+ """This generates a random password, saves it in hashed form, and returns
|
|
|
+ it to the user in cleartext.
|
|
|
+ """
|
|
|
+ vpn = get_object_or_404(VPNSubscription, pk=vpn_id,
|
|
|
+ administrative_subscription__member__user=request.user)
|
|
|
+ # This function has nothing to here, but it's convenient.
|
|
|
+ password = User.objects.make_random_password()
|
|
|
+ vpn.password = password
|
|
|
+ # This will hash the password automatically
|
|
|
+ vpn.full_clean()
|
|
|
+ vpn.save()
|
|
|
+ return render_to_response('vpn/password.html', {"vpn": vpn,
|
|
|
+ "password": password})
|