REG: new user is saved in django_auth_user table[needed for password reset]
[myslice.git] / portal / registrationview.py
index 8f7032b..d2a04a9 100644 (file)
@@ -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 = 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"
 
@@ -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,6 +142,8 @@ class RegistrationView (FreeAccessView):
                     keypair       = keypair,
                 )
                 b.save()
+                # saves the user to django auth_user table [needed for password reset]
+                user = User.objects.create_user(reg_fname, 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}
@@ -154,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)
@@ -167,7 +173,7 @@ class RegistrationView (FreeAccessView):
                 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', ''),