Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Essential code layout in place to create Nimbus User after

creation of Django User, but needs more to be fully working.
  • Loading branch information...
commit 0e13f00e9d3597b61a5942e889e420ecd67b83ae 1 parent 5f9e30d
@clemesha-ooi clemesha-ooi authored
View
11 web/src/python/nimbusweb/portal/nimbus/adminops.py
@@ -151,6 +151,17 @@ def _newuser(newuserform, request_files):
# were successfully used which does not make sense, they should only be
# filled in to help the user re-enter content when there is an error.
return (None, noerror_flash_msg, None)
+
+def nimbus_user_create(user_instance):
+ """Use the Nimbus API to register a new Nimbus User.
+ """
+ from nimbusrest.connection import Connection
+ service_uri = settings.NIMBUS_SERVICE_URI
+ conn = Connection(service_uri) #, nimbus_key, nimbus_secret)
+ body = {"username":user_instance.username} #XXX what else is needed?
+ response = conn.post_json("/user/create", body) #let caller handle errors
+ return response
+
def ok_token_attempt(ipaddress, maxcount):
"""Return False if this IP has submitted too many tokens"""
View
22 web/src/python/nimbusweb/portal/nimbus/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User, UserManager
+import adminops
class TokenFailure(models.Model):
ip = models.IPAddressField(primary_key=True)
@@ -31,3 +32,24 @@ def user_post_save(sender, instance, **kwargs):
profile, new = UserProfile.objects.get_or_create(user=instance)
models.signals.post_save.connect(user_post_save, User)
+
+def complete_nimbus_user_create(sender, instance, **kwargs):
+ """Save response data from a successful `Nimbus User`
+ creation attempt, or, in the case of failure, remove
+ the recently created `Django User` and send failure
+ message back to User create Form.
+ """
+ print "complete_nimbus_user_create => ", sender, instance, kwargs
+ # only attempt to create Nimbus User on Django User creation.
+ if kwargs.get('created'):
+ try:
+ response = adminops.nimbus_user_create(instance)
+ except:
+ #Nimbus User failed to be created, delete Django User
+ instance.delete() #XXX how to handle this?
+ raise #forms.Error("Failed to create Nimbus user at '%s'" % settings.NIMBUS_SERVICE_URI)
+ up = UserProfile(user=instance)
+ up.registration_complete = True
+ #XXX what other data in "response" needs to be saved in UserProfile??
+
+models.signals.post_save.connect(complete_nimbus_user_create, User)
Please sign in to comment.
Something went wrong with that request. Please try again.