Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into fibre
[myslice.git] / portal / registrationview.py
index 7967a91..199c173 100644 (file)
@@ -17,7 +17,9 @@ from manifoldapi.manifoldapi    import execute_admin_query
 from manifold.core.query        import Query
 
 from portal.models              import PendingUser
-from portal.actions             import create_pending_user
+#from portal.actions             import create_pending_user
+# Edelberto - LDAP
+from portal.actions             import create_pending_user, ldap_create_user
 
 from myslice.theme import ThemeView
 
@@ -38,7 +40,7 @@ class RegistrationView (FreeAccessView, ThemeView):
         """
         errors = []
 
-        authorities_query = Query.get('authority').select('name', 'authority_hrn')
+        authorities_query = Query.get('authority').select('name','authority_hrn')
         authorities = execute_admin_query(wsgi_request, authorities_query)
         if authorities is not None:
             authorities = sorted(authorities)
@@ -57,13 +59,17 @@ class RegistrationView (FreeAccessView, ThemeView):
             current_site = Site.objects.get_current()
             current_site = current_site.domain
 
-            authorities_query = Query.get('authority').select('name', 'authority_hrn')
-            authorities = execute_admin_query(wsgi_request, authorities_query)
+            #authorities_query = Query.get('authority').select('name', 'authority_hrn')
+            #authorities = execute_admin_query(wsgi_request, authorities_query)
     
             for authority in authorities:
                 if authority['name'] == wsgi_request.POST.get('org_name', ''):
                     authority_hrn = authority['authority_hrn']     
 
+            # Handle the case when the template uses only hrn and not name
+            if not authority_hrn:
+                authority_hrn = wsgi_request.POST.get('org_name', '')
+
             post_email = wsgi_request.POST.get('email','').lower()
             salt = randint(1,100000)
             email_hash = md5(str(salt)+post_email).hexdigest()
@@ -77,6 +83,7 @@ class RegistrationView (FreeAccessView, ThemeView):
                 'password'      : wsgi_request.POST.get('password',      ''),
                 'current_site'  : current_site,
                 'email_hash'    : email_hash,
+                'pi'            : '',
                 'validation_link': 'http://' + current_site + '/portal/email_activation/'+ email_hash
             }
 
@@ -142,13 +149,30 @@ class RegistrationView (FreeAccessView, ThemeView):
                 ALLOWED_EXTENSIONS =  ['.pub','.txt']
                 if file_extension not in ALLOWED_EXTENSIONS or not re.search(r'ssh-rsa',file_content):
                     errors.append('Please upload a valid RSA public key.')
-
-                user_request['private_key'] = None
+                # user_request['private_key'] can't be Null because all db fields are set as NOT NULL
+                user_request['private_key'] = ""
                 user_request['public_key']  = file_content
                 
             if not errors:
+                '''
+                try:
+                    # verify if is a  LDAP 
+                    mail = user_detail['email']
+                    login = mail.split('@')[0]
+                    org = mail.split('@')[1]
+                    o = org.split('.')[-2]
+                    dc = org.split('.')[-1]
+                    # To know if user is a LDAP user - Need to has a 'dc' identifier
+                    if dc == 'br' or 'eu':
+                        # LDAP insert directly - but with userEnable = FALSE
+                        ldap_create_user(wsgi_request, user_request, user_detail)
+                   
+                except Exception, e:
+                    print "LDAP: problem em access the LDAP with this credentail" 
+                '''
                 create_pending_user(wsgi_request, user_request, user_detail)
                 self.template_name = 'user_register_complete.html'
+            
                 return render(wsgi_request, self.template, {'theme': self.theme}) 
 
         else: