Browse Source

Generate VPN passwords

Baptiste Jonglez 10 years ago
parent
commit
b9d8753c7f
4 changed files with 34 additions and 2 deletions
  1. 1 0
      coin/urls.py
  2. 8 0
      coin/vpn/templates/vpn/password.html
  3. 7 0
      coin/vpn/urls.py
  4. 18 2
      coin/vpn/views.py

+ 1 - 0
coin/urls.py

@@ -17,6 +17,7 @@ urlpatterns = patterns(
 
     url(r'^members/', include('coin.members.urls', namespace='members')),
     url(r'^billing/', include('coin.billing.urls', namespace='billing')),
+    url(r'^vpn/', include('coin.vpn.urls', namespace='vpn')),
 
     url(r'^admin/', include(admin.site.urls)),
 

+ 8 - 0
coin/vpn/templates/vpn/password.html

@@ -0,0 +1,8 @@
+{% extends "base.html" %}
+
+{% block content %}
+<h2>VPN password generation</h2>
+<p>Generated password for VPN <strong>{{ vpn.login }}</strong>:</p>
+<p><strong>{{ password }}</strong></p>
+<p>Don't forget it, it will only be displayed once (we don't store it in clear text).  If you forget this password, you will have to generate a new one.</p>
+{% endblock %}

+ 7 - 0
coin/vpn/urls.py

@@ -0,0 +1,7 @@
+from django.conf.urls import patterns, url
+from coin.vpn import views
+
+urlpatterns = patterns(
+    '',
+    url(r'^password/(?P<vpn_id>.+)$', views.generate_password, name="generate_password"),
+)

+ 18 - 2
coin/vpn/views.py

@@ -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})