- UserModel = get_user_model()
-
- #POST value validation
- if (re.search(r'^[\w+\s.@+-]+$', reg_fname)==None):
- errors.append('First Name may contain only letters, numbers, spaces and @/./+/-/_ characters.')
- if (re.search(r'^[\w+\s.@+-]+$', reg_lname) == None):
- errors.append('Last Name may contain only letters, numbers, spaces and @/./+/-/_ characters.')
- # checking in django_db !!
- if PendingUser.objects.filter(email__iexact=reg_email):
- errors.append('Email is pending for validation. Please provide a new email address.')
- if UserModel._default_manager.filter(email__iexact=reg_email):
- errors.append('This email is not usable. Please contact the administrator or try with another email.')
- for user_detail in user_details:
- if user_detail['email']==reg_email:
- errors.append('Email already registered in Manifold. Please provide a new email address.')
-
-# XXX TODO: Factorize with portal/accountview.py
- if 'generate' in request.POST['question']:
- from Crypto.PublicKey import RSA
- private = RSA.generate(1024)
- private_key = json.dumps(private.exportKey())
- public = private.publickey()
- public_key = json.dumps(public.exportKey(format='OpenSSH'))
-
-# # Generate public and private keys using SFA Library
-# from sfa.trust.certificate import Keypair
-# k = Keypair(create=True)
-# public_key = k.get_pubkey_string()
-# private_key = k.as_pem()
-# private_key = ''.join(private_key.split())
-# public_key = "ssh-rsa " + public_key
- # Saving to DB
- account_config = '{"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')
- #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()
- file_name = up_file.name
- 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):
- account_config = '{"user_public_key":"'+ file_content + '", "user_hrn":"'+ user_hrn +'"}'
- account_config = re.sub("\r", "", account_config)
- account_config = re.sub("\n", "\\n",account_config)
- account_config = ''.join(account_config.split())
- 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.')
-
- #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,
- last_name = reg_lname,
- #affiliation = reg_aff,
- authority_hrn = reg_auth,
- #login = reg_login,
- email = reg_email,
- password = request.POST['password'],
- keypair = account_config,
- pi = '',
- )
- b.save()
- # 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
- user_config = '{"firstname":"'+ reg_fname + '", "lastname":"'+ reg_lname + '", "authority":"'+ reg_auth + '"}'
- user_params = {'email': reg_email, 'password': request.POST['password'], 'config': user_config, 'status': 1}
- 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
- account_params = {'platform_id': 5, 'user_id': user_id, 'auth_type': auth_type, 'config': account_config}
- manifold_add_account(request,account_params)
-
- # Send email
- ctx = {
- 'first_name' : reg_fname,
- 'last_name' : reg_lname,
- 'authority_hrn' : reg_auth,
- 'email' : reg_email,
- 'user_hrn' : user_hrn,
- 'public_key' : public_key,
- }
+ # get the domain url
+ current_site = Site.objects.get_current()
+ current_site = current_site.domain
+
+ print "############ BREAKPOINT 3 #################"
+ post_email = wsgi_request.POST.get('email','').lower()
+ salt = randint(1,100000)
+ email_hash = md5(str(salt)+post_email).hexdigest()
+ #email_hash = md5(post_email).digest().encode('base64')[:-1]
+ user_request = {
+ 'first_name' : wsgi_request.POST.get('firstname', ''),
+ 'last_name' : wsgi_request.POST.get('lastname', ''),
+ 'authority_hrn' : wsgi_request.POST.get('org_name', ''),
+ 'email' : post_email,
+ 'password' : wsgi_request.POST.get('password', ''),
+ 'current_site' : current_site,
+ 'email_hash' : email_hash,
+ 'pi' : '',
+ 'validation_link': 'https://' + current_site + '/portal/email_activation/'+ email_hash
+ }
+
+ print "############ BREAKPOINT 4 #################"
+ auth = wsgi_request.POST.get('org_name', None)
+ if auth is None:
+ errors.append('Organization required: please select one or request its addition')
+ else:
+
+ print "############ BREAKPOINT 5 #################"