X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fregistrationview.py;h=b9f35ffb53d3f0e63ca3f72f9f91c32729f89482;hb=4fa84eb6c39eed3d7ae9125e0368eb3271908abf;hp=aebe1817981f02212122ee11b5fbf15435a9faa8;hpb=86bfd08412d81204e93463ad55d40728db7fa20f;p=myslice.git diff --git a/portal/registrationview.py b/portal/registrationview.py index aebe1817..b9f35ffb 100644 --- a/portal/registrationview.py +++ b/portal/registrationview.py @@ -15,7 +15,7 @@ from manifold.manifoldapi import execute_admin_query from manifold.core.query import Query from portal.models import PendingUser -from portal.actions import authority_get_pi_emails +from portal.actions import authority_get_pi_emails, manifold_add_user,manifold_add_account # since we inherit from FreeAccessView we cannot redefine 'dispatch' # so let's override 'get' and 'post' instead @@ -37,13 +37,13 @@ class RegistrationView (FreeAccessView): #onelab_enabled_query = Query.get('local:platform').filter_by('platform', '==', 'ple').filter_by('disabled', '==', 'False') #onelab_enabled = not not execute_admin_query(request, onelab_enabled_query) #if onelab_enabled: - if True: - print "ONELAB ENABLED" - authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos']) - else: - print "FIREXP ENABLED" + #if True: + # print "ONELAB ENABLED" + # authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos']) + #else: + # print "FIREXP ENABLED" - authorities = execute_admin_query(request, authorities_query) + #authorities = execute_admin_query(request, authorities_query) # xxx tocheck - if authorities is empty, it's no use anyway # (users won't be able to validate the form anyway) @@ -93,7 +93,8 @@ class RegistrationView (FreeAccessView): # private_key = ''.join(private_key.split()) # public_key = "ssh-rsa " + public_key # Saving to DB - keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":'+ user_hrn + '}' + keypair = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":"'+ user_hrn + '"}' + auth_type = 'managed' #keypair = re.sub("\r", "", keypair) #keypair = re.sub("\n", "\\n", keypair) #keypair = keypair.rstrip('\r\n') @@ -105,10 +106,11 @@ class RegistrationView (FreeAccessView): file_extension = os.path.splitext(file_name)[1] allowed_extension = ['.pub','.txt'] if file_extension in allowed_extension and re.search(r'ssh-rsa',file_content): - keypair = '{"user_public_key":"'+ file_content +'"}' + keypair = '{"user_public_key":"'+ file_content + '", "user_hrn":"'+ user_hrn +'"}' keypair = re.sub("\r", "", keypair) keypair = re.sub("\n", "\\n",keypair) keypair = ''.join(keypair.split()) + auth_type = 'user' # for sending email public_key = file_content else: @@ -117,6 +119,7 @@ class RegistrationView (FreeAccessView): #b = PendingUser(first_name=reg_fname, last_name=reg_lname, affiliation=reg_aff, # email=reg_email, password=request.POST['password'], keypair=keypair) #b.save() + #saving to django db 'portal_pendinguser' table if not errors: b = PendingUser( first_name = reg_fname, @@ -129,17 +132,20 @@ class RegistrationView (FreeAccessView): keypair = keypair, ) b.save() - + #saving to manifold + config = '{"firstname":'+ reg_fname + ', "lastname":'+ reg_lname + ', "authority":"'+ reg_auth + '"}' + user_params = {'email': reg_email, 'password': request.POST['password'], 'config': config} + manifold_add_user(request,user_params) # Send email ctx = { 'first_name' : reg_fname, 'last_name' : reg_lname, 'authority_hrn' : reg_auth, - 'email' : reg_email, + 'email' : reg_email, + 'user_hrn' : user_hrn, 'keypair' : 'Public Key :' + public_key, 'cc_myself' : True # form.cleaned_data['cc_myself'] } - recipients = authority_get_pi_emails(request,reg_auth) if ctx['cc_myself']: @@ -148,7 +154,20 @@ class RegistrationView (FreeAccessView): msg = render_to_string('user_request_email.txt', ctx) send_mail("Onelab New User request for %s submitted"%reg_email, msg, reg_email, recipients) - return render(request, 'user_register_complete.html') + #return render(request, 'user_register_complete.html') + + #creating local:account in manifold + user_query = Query().get('local:user').select('user_id','email') + user_details = execute_admin_query(self.request, user_query) + + for user_detail in user_details: + if user_detail['email']==reg_email: + user_id = user_detail['user_id'] + #print "test" + #print user_id + user_params = {'platform_id': 5, 'user_id': user_id, 'auth_type': auth_type, 'config': keypair} + manifold_add_account(request,user_params) + return render(request, 'user_register_complete.html') template_env = { 'topmenu_items': topmenu_items('Register', request), @@ -159,7 +178,7 @@ class RegistrationView (FreeAccessView): 'authority_hrn': request.POST.get('authority_hrn', ''), 'email': request.POST.get('email', ''), 'password': request.POST.get('password', ''), - 'authorities': authorities, + #'authorities': authorities, } template_env.update(page.prelude_env ()) return render(request, 'registration_view.html',template_env)