X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fregistrationview.py;h=64eca81f08ffebaa40f1fe444b7f97acc38b3e9b;hb=136ec4d6c95beb2537cc5e61615cdee741529f60;hp=f28ccb7f405335e6b1b2ffdc8feeaf72c5f0b544;hpb=8fd758c9a6e7b9b4f7fde3abe6948b59fbad8146;p=myslice.git diff --git a/portal/registrationview.py b/portal/registrationview.py index f28ccb7f..64eca81f 100644 --- a/portal/registrationview.py +++ b/portal/registrationview.py @@ -2,14 +2,14 @@ import os.path, re import json from django.core.mail import send_mail - +from django.contrib.auth.models import User from django.views.generic import View from django.template.loader import render_to_string from django.shortcuts import render from unfold.page import Page from unfold.loginrequired import FreeAccessView -from ui.topmenu import topmenu_items +from ui.topmenu import topmenu_items_live from manifold.manifoldapi import execute_admin_query from manifold.core.query import Query @@ -31,15 +31,16 @@ class RegistrationView (FreeAccessView): def get_or_post (self, request, method): errors = [] - #authorities_query = Query.get('authority').\ - # select('name', 'authority_hrn') + # Using cache manifold-tables to get the list of authorities faster + authorities_query = Query.get('authority').select('name', 'authority_hrn') - onelab_enabled_query = Query.get('local:platform').filter_by('platform', '==', 'ple').filter_by('disabled', '==', 'False') + #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']) + #authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos']) + # Now using Cache else: print "FIREXP ENABLED" @@ -78,10 +79,10 @@ class RegistrationView (FreeAccessView): errors.append('Last Name may contain only letters, numbers, spaces and @/./+/-/_ characters.') # XXX validate authority hrn !! if PendingUser.objects.filter(email__iexact=reg_email): - errors.append('Email is pending for validation.Please provide a new email address.') + errors.append('Email is pending for validation. Please provide a new email address.') for user_detail in user_details: if user_detail['email']==reg_email: - errors.append('Email already exists in Manifold.Please provide a new email address.') + errors.append('Email already exists in Manifold. Please provide a new email address.') # XXX TODO: Factorize with portal/accountview.py if 'generate' in request.POST['question']: @@ -105,6 +106,8 @@ class RegistrationView (FreeAccessView): #keypair = re.sub("\n", "\\n", keypair) #keypair = keypair.rstrip('\r\n') #keypair = ''.join(keypair.split()) + #for sending email: removing existing double qoute + public_key = public_key.replace('"', ''); else: up_file = request.FILES['user_public_key'] file_content = up_file.read() @@ -119,6 +122,7 @@ class RegistrationView (FreeAccessView): auth_type = 'user' # for sending email public_key = file_content + public_key = ''.join(public_key.split()) else: errors.append('Please upload a valid RSA public key [.txt or .pub].') @@ -138,10 +142,17 @@ class RegistrationView (FreeAccessView): keypair = keypair, ) b.save() - #saving to manifold - config = '{"firstname":'+ reg_fname + ', "lastname":'+ reg_lname + ', "authority":"'+ reg_auth + '"}' + # saves the user to django auth_user table [needed for password reset] + user = User.objects.create_user(reg_email, reg_email, request.POST['password']) + #creating user to manifold local:user + 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) + manifold_add_user(request,user_params) + #creating local:account in manifold + user_id = user_detail['user_id']+1 # the user_id for the newly created user in local:user + user_params = {'platform_id': 5, 'user_id': user_id, 'auth_type': auth_type, 'config': keypair} + manifold_add_account(request,user_params) + # Send email ctx = { 'first_name' : reg_fname, @@ -149,7 +160,7 @@ class RegistrationView (FreeAccessView): 'authority_hrn' : reg_auth, 'email' : reg_email, 'user_hrn' : user_hrn, - 'keypair' : 'Public Key :' + public_key, + 'keypair' : 'Public Key: ' + public_key, 'cc_myself' : True # form.cleaned_data['cc_myself'] } recipients = authority_get_pi_emails(request,reg_auth) @@ -159,20 +170,10 @@ 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') - - #creating local:account in manifold - for user_detail in user_details: - if user_detail['email']==reg_email: - user_id = user_detail['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') + return render(request, 'user_register_complete.html') template_env = { - 'topmenu_items': topmenu_items('Register', request), + 'topmenu_items': topmenu_items_live('Register', page), 'errors': errors, 'firstname': request.POST.get('firstname', ''), 'lastname': request.POST.get('lastname', ''),