Permalink
Browse files

User creation method forms working, with stubbed out remote Nimbus Us…

…er creation calls.
  • Loading branch information...
1 parent 7eb4156 commit 4e7dfc246928981789542525d615cbe1023e1327 @clemesha-ooi clemesha-ooi committed Feb 4, 2010
@@ -2,7 +2,11 @@
{% extends "base.html" %}
{% block title %}Create a new User{% endblock %}
{% block content %}
-
- <p>{{ method }}</p>
+ <a href="../">&laquo;&nbsp;Back to User create options</a>
+ <h3>{{ methodinfo }}</h3>
+ <form enctype="multipart/form-data" method="post" action="">
+ {{ form.as_p }}
+ <input type="submit" value="Create User">
+ </form>
{% endblock %}
@@ -2,6 +2,7 @@
{% block title %}New User successfully created{% endblock %}
{% block content %}
- <p>New User successfully created</p>
+ <h3>New User successfully created</h3>
+ <p>Email the following registration link to the new User: <pre>{{ url }}{{ token }}</pre></p>
{% endblock %}
@@ -1,2 +1,17 @@
from django import forms
+class NewUserForm(forms.Form):
+ username = forms.CharField()
+ firstname = forms.CharField()
+ lastname = forms.CharField()
+ email = forms.EmailField()
+
+class CertKeyForm(NewUserForm):
+ cert = forms.FileField()
+ key = forms.FileField()
+
+class DNForm(NewUserForm):
+ DN = forms.CharField()
+
+class AutoCreateForm(NewUserForm):
+ pass
@@ -1,8 +1,7 @@
from django.conf.urls.defaults import *
-from django.contrib.auth.views import login, logout, password_change, password_change_done
urlpatterns = patterns('nimbusweb.portal.usercreate.views',
(r'^$', 'index'),
(r'^(?P<method>.*)/$', 'method'),
- (r'^success/$', 'success'),
+ (r'^success$', 'success'),
)
@@ -0,0 +1,16 @@
+
+def create_nimbus_user_stub(dn):
+ nimbus_userid = "test_nimbus_userid"
+ return nimbus_userid
+create_nimbus_user = create_nimbus_user_stub
+
+def extract_dn_stub(cert, key):
+ new_users_dn = "test_dn"
+ return new_users_dn
+extract_dn = extract_dn_stub
+
+def autocreate_cert_stub():
+ new_users_dn = "test_dn"
+ return new_users_dn
+autocreate_cert = autocreate_cert_stub
+
@@ -2,7 +2,8 @@
from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponseRedirect
-#from forms import CertKeyForm, DNForm
+import util
+from forms import CertKeyForm, DNForm, AutoCreateForm
USER_CREATE_METHODS = (
("certkey", "Provide User's Cert and Key files", "The DN will be extracted from upload keys to create a new User."),
@@ -19,45 +20,62 @@ def method(request, method):
if method not in ["certkey", "dn", "autocreate"]:
raise Http404
+ dn = None
if method == "certkey":
+ methodinfo = USER_CREATE_METHODS[0][1]
if request.method == "POST":
# get cert and key
- form = CertKeyForm(request.POST)
+ form = CertKeyForm(request.POST, request.FILES)
if form.is_valid():
cert = form.cleaned_data["cert"]
key = form.cleaned_data["key"]
+ print cert, key, type(cert), type(key)
try:
dn = util.extract_dn(cert, key)
except:
+ #TODO: better error:
raise Exception("Failed getting DN from cert and key")
else:
form = CertKeyForm()
if method == "dn":
+ methodinfo = USER_CREATE_METHODS[1][1]
if request.method == "POST":
form = DNForm(request.POST)
if form.is_valid():
- dn = form.cleaned_data["dn"]
+ dn = form.cleaned_data["DN"]
else:
form = DNForm()
if method == "autocreate":
+ methodinfo = USER_CREATE_METHODS[2][1]
if request.method == "POST":
#No form data needed, correct?
- dn = util.autocreate_cert()
+ form = AutoCreateForm(request.POST)
+ if form.is_valid():
+ dn = util.autocreate_cert()
+ else:
+ form = AutoCreateForm()
- try:
- nimbus_userid = util.create_nimbus_user(dn) #if this fails, new User is deleted.
- #TODO save 'nimbus_userid' to UserProfile here, or does util.create_nimbus_user do it?
- except:
- raise Exception("Failed creating Nimbus User")
+ if dn is not None:
+ try:
+ username = form.cleaned_data["username"]
+ firstname = form.cleaned_data["firstname"]
+ lastname = form.cleaned_data["lastname"]
+ email = form.cleaned_data["email"]
+ nimbus_userid = util.create_nimbus_user(dn) #if this fails, new User is deleted.
+ #TODO save 'nimbus_userid' to UserProfile here, or does util.create_nimbus_user do it?
+ print "=== final data ==> ", username, firstname, lastname, email, nimbus_userid
+ unique_new_user_token="abc123"
+ return HttpResponseRedirect("/usercreate/success?token="+unique_new_user_token)
+ except:
+ raise Exception("Failed creating Nimbus User")
- if request.method == "POST":
- #if we get this far, Django and Nimbus User have just been successfully created.
- HttpResponseRedirect("/usercreate/success")
- return render_to_response('usercreate/method.html', {"form":form, "method":method})
+ return render_to_response('usercreate/method.html', {"form":form, "method":method, "methodinfo":methodinfo})
@login_required
def success(request):
- return render_to_response('usercreate/success.html')#, {"details":details})
+ token = request.GET.get("token")
+ url = "http://localhost:1443/register/"#settings.APP_URL
+ return render_to_response('usercreate/success.html', {"url":url, "token":token})

0 comments on commit 4e7dfc2

Please sign in to comment.