AiC and REST login
[myslice.git] / portal / registrationview.py
index d1c12ca..76d712d 100644 (file)
@@ -1,4 +1,5 @@
-import os.path, re
+import os.path
+import re
 import json
 from random     import randint
 from hashlib    import md5
@@ -8,7 +9,6 @@ from django.template.loader     import render_to_string
 
 from django.shortcuts           import render
 from django.contrib.auth        import get_user_model
-from django.contrib.sites.models import Site
 
 from unfold.page                import Page
 from unfold.loginrequired       import FreeAccessView
@@ -18,9 +18,10 @@ 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, getAuthorities
 
 from myslice.theme import ThemeView
+from myslice.settings import logger
 
 import activity.user
 
@@ -40,15 +41,20 @@ class RegistrationView (FreeAccessView, ThemeView):
         """
         """
         errors = []
-        authority_hrn = None
-        # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
-        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, key=lambda k: k['authority_hrn'])
-            authorities = sorted(authorities, key=lambda k: k['name'])
+
+        authorities = getAuthorities(wsgi_request, admin = True)
+
+        #authority_hrn = None
+        ## REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
+        #authorities_query = Query.get('authority').select('name', 'authority_hrn')
+        #authorities = execute_admin_query(wsgi_request, authorities_query)
+        #if authorities is not None:
+        #    # Remove the root authority from the list
+        #    matching = [s for s in authorities if "." in s['authority_hrn']]
+        #    authorities = sorted(matching, key=lambda k: k['authority_hrn'])
+        #    authorities = sorted(matching, key=lambda k: k['name'])
         
-        print "############ BREAKPOINT 1 #################"
+        logger.debug("############ BREAKPOINT 1 #################")
         # Page rendering
         page = Page(wsgi_request)
 
@@ -58,16 +64,18 @@ class RegistrationView (FreeAccessView, ThemeView):
 
         page.add_css_files ( [ "css/onelab.css", "css/registration.css", "css/jquery.qtip.min.css", "css/jquery.ui.combobox.css" ] )
         page.expose_js_metadata()
-        print "############ BREAKPOINT 2 #################"
+        logger.debug("############ BREAKPOINT 2 #################")
         if method == 'POST':
             reg_form = {}
             # The form has been submitted
             
-            # get the domain url
-            current_site = Site.objects.get_current()
-            current_site = current_site.domain
-           
-            print "############ BREAKPOINT 3 #################"
+            if wsgi_request.is_secure():
+                current_site = 'https://'
+            else:
+                current_site = 'http://'
+            current_site += wsgi_request.META['HTTP_HOST']
+
+            logger.debug("############ BREAKPOINT 3 #################")
             post_email = wsgi_request.POST.get('email','').lower()
             salt = randint(1,100000)
             email_hash = md5(str(salt)+post_email).hexdigest()
@@ -84,13 +92,13 @@ class RegistrationView (FreeAccessView, ThemeView):
                 'validation_link': current_site + '/portal/email_activation/'+ email_hash
             }
 
-            print "############ BREAKPOINT 4 #################"
+            logger.debug("############ BREAKPOINT 4 #################")
             auth = wsgi_request.POST.get('org_name', None)
-            if auth is None:
+            if auth is None or auth == "":
                 errors.append('Organization required: please select one or request its addition')
             else:
                
-                print "############ BREAKPOINT 5 #################"
+                logger.debug("############ BREAKPOINT 5 #################")
                 
                 # Construct user_hrn from email (XXX Should use common code)
                 split_email = user_request['email'].split("@")[0] 
@@ -180,7 +188,7 @@ class RegistrationView (FreeAccessView, ThemeView):
                     return render(wsgi_request, self.template, {'theme': self.theme}) 
 
         else:
-            print "############ BREAKPOINT A #################"
+            logger.debug("############ BREAKPOINT A #################")
             user_request = {}
             ## this is coming from onelab website onelab.eu
             reg_form = {
@@ -190,7 +198,7 @@ class RegistrationView (FreeAccessView, ThemeView):
                 }
             # log user activity
             activity.user.signup(self.request)
-            print "############ BREAKPOINT B #################"
+            logger.debug("############ BREAKPOINT B #################")
 
         template_env = {
           #'topmenu_items': topmenu_items_live('Register', page),
@@ -201,5 +209,5 @@ class RegistrationView (FreeAccessView, ThemeView):
         template_env.update(user_request)
         template_env.update(reg_form)
         template_env.update(page.prelude_env ())
-        print "############ BREAKPOINT C #################"
+        logger.debug("############ BREAKPOINT C #################")
         return render(wsgi_request, self.template,template_env)