|
@@ -6,22 +6,24 @@ from coin.vpn.models import VPNSubscription
|
|
|
|
|
|
|
|
|
class VPNView(DetailView):
|
|
|
- def get_object(self):
|
|
|
+
|
|
|
+ def get_object(self):
|
|
|
return get_object_or_404(VPNSubscription, pk=self.args[0],
|
|
|
administrative_subscription__member__user=self.request.user)
|
|
|
|
|
|
|
|
|
-def generate_password(request, vpn_id):
|
|
|
+class VPNGeneratePasswordView(VPNView):
|
|
|
"""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})
|
|
|
+
|
|
|
+ def get_context_data(self, **kwargs):
|
|
|
+ context = super(VPNGeneratePasswordView, self).get_context_data(**kwargs)
|
|
|
+ # Generate a new random password and save it
|
|
|
+ password = User.objects.make_random_password()
|
|
|
+ self.object.password = password
|
|
|
+ # This will hash the password automatically
|
|
|
+ self.object.full_clean()
|
|
|
+ self.object.save()
|
|
|
+ context['password'] = password
|
|
|
+ return context
|