Merge branch 'jordan' of ssh://git.onelab.eu/git/myslice into jordan
authorJordan Augé <jordan.auge@lip6.fr>
Wed, 28 Aug 2013 08:42:11 +0000 (10:42 +0200)
committerJordan Augé <jordan.auge@lip6.fr>
Wed, 28 Aug 2013 08:42:11 +0000 (10:42 +0200)
Conflicts:
portal/views.py

README
manifold/manifoldapi.py
portal/templates/my_account.html
portal/templates/slice_request.html
portal/urls.py
portal/views.py

diff --git a/README b/README
index 175e65b..5ababdb 100644 (file)
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-his file documents the contents of this module
+This file documents the contents of this module
 
 See the devel/ subdir for more devel-oriented doc.
 
@@ -219,3 +219,19 @@ that would reset all-static/ and all-templates/ for you from the other contents
 
 
 
+======== update django database to reflect changes in existing models without any migration system (e.g., south) =========
+
+$python manage.py reset <your_app>
+#Django 1.5.1
+$python manage.py flush
+
+This will update the database tables for your app, but will completely destroy any data that existed in those tables. 
+If the changes you made to your app model do not break your old schema (for instance, you added a new, optional field) 
+you can simply dump the data before and reload it afterwards, like so:
+
+
+$python manage.py dumpdata <your_app> > temp_data.json
+$python manage.py reset <your_app>
+$python manage.py loaddata temp_data.json
+
+If your changes break your old schema this won't work - in which case tools like south or django evolution are great.
index e7d6a1b..29c6c98 100644 (file)
@@ -62,7 +62,7 @@ class ManifoldAPI:
         return func
 
 def execute_query(request, query):
-    if not 'manifold' in request.session:
+    if not 'manifold' in request.session or not 'auth' in request.session['manifold']:
         print "W: Used hardcoded demo account for execute_query"
         manifold_api_session_auth = {'AuthMethod': 'password', 'Username': 'demo', 'AuthString': 'demo'}
     else:
index d069cfe..3284fdb 100644 (file)
@@ -18,7 +18,7 @@
     </div>
     <div class='ms-dashboard-content' id='tophat__list__user_hrn'>
             <div id="main">
-                    <div id="middle">
+                    <div id="middle" align="center">
                        <form id="editForm"  method="POST" action="acc_process" enctype="multipart/form-data">
                                                {% csrf_token %}
                        <table class="profile">          
@@ -64,7 +64,7 @@
                                 <tr class="even">
                                             <td class="key">Full Name</td>
                                             <td class="value">
-                                                    <span id="nameval" class="value" >Yasin Rahman </span>
+                                                    <span id="nameval" class="value" >{{ users }} </span>
                                                     <span class="hide_this" id="span_name">
                                                             <button type="button" class="cancel" title="Cancel" id="cancel_name_change"> Cancel </button>
                                                             
index e60e881..acaf2df 100644 (file)
@@ -7,12 +7,18 @@
 
 {% block unfold1_main %}
 
-  <h1>Request a Slice</h1>
+<link rel="stylesheet" type="text/css" href="{{STATIC_URL}}/css/register.css" />
+
+<form id="commentForm" action="" method="post">{% csrf_token %}
+
+<div class="OneLabTitle" style="margin-bottom:20px;">
+         <h2>Request a Slice</h2>
+</div>
 
-<form action="#" method="post">{% csrf_token %}
 {{ form.as_p }}
-<input type="submit" value="Submit" />
+<p style="text-align: center;width: 80%;">
+       <input type="submit" value="Submit" />
+</p>
 </form>
 
 {% endblock %}
index 31c8908..c5c270f 100644 (file)
@@ -22,7 +22,7 @@
 
 from django.conf.urls import patterns, include, url
 from portal           import views
-from portal.views     import DashboardView, PresViewView, PlatformsView, PlatformView, ValidatePendingView # UserRegisterView, UserValidateView
+from portal.views     import DashboardView, PresViewView, PlatformsView, PlatformView, ValidatePendingView, AccountView # UserRegisterView, UserValidateView
 from portal.util      import TemplateView
 
 # DEPRECATED #named_register_forms = (
@@ -43,11 +43,11 @@ urlpatterns = patterns('',
     #url(r'^user/validate/?$', UserValidateView.as_view(), name='user_validate'),
     url(r'^dashboard/?$', DashboardView.as_view(), name='dashboard'),
     #url(r'^my_account/?$', MyAccountView.as_view(), name='my_account'),
-    url(r'^account/?$', views.my_account),
+    url(r'^account/?$', AccountView.as_view(), name='account'),
     url(r'^platforms/?$', PlatformsView.as_view(), name='platforms'),
     #url(r'^portal/platform/?$', PlatformView.platform_view(), name='platform'),
     url(r'^platform/(?P<platformname>[\w\.]+)/?$', PlatformView.as_view(), name='platform'),
-    url(r'^acc_process/?$', views.acc_process),
+    url(r'^account/acc_process/?$', views.acc_process),
     url(r'^register/?$', views.register_4m_f4f),
     #url(r'^reg_process/?$', views.reg_4m_f4f_process),
     url(r'^contact/?$', views.contact),
index 87f6cb6..a29beae 100644 (file)
@@ -29,6 +29,8 @@ from django.views.generic.base   import TemplateView
 from django.shortcuts            import render
 from django.template.loader      import render_to_string
 from django.core.mail            import send_mail
+from django.utils.decorators     import method_decorator
+from django.contrib.auth.decorators import login_required
 
 from plugins.lists.simplelist    import SimpleList
 from plugins.hazelnut            import Hazelnut
@@ -52,6 +54,11 @@ import os, re
 
 class DashboardView(TemplateView):
     template_name = "dashboard.html"
+    
+    #This view requires login 
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(DashboardView, self).dispatch(*args, **kwargs)
 
     def get_context_data(self, **kwargs):
         # We might have slices on different registries with different user accounts 
@@ -475,16 +482,6 @@ class DashboardView(TemplateView):
 # DEPRECATED #        context.update(page.prelude_env())
 # DEPRECATED #        return context
 
-
-
-# View for my_account form
-def my_account(request):
-    return render(request, 'my_account.html', {
-        #'form': form,
-        'topmenu_items': topmenu_items('My Account', request),
-        'username': the_user (request)
-    })
-
 # View for platforms
 class PlatformsView(TemplateView):
     template_name = "platforms.html"
@@ -492,7 +489,8 @@ class PlatformsView(TemplateView):
     def get_context_data(self, **kwargs):
         page = Page(self.request)
 
-        network_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform','platform_longname','gateway_type')
+        #network_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform','platform_longname','gateway_type')
+        network_query  = Query().get('local:platform').select('platform','platform_longname','gateway_type')
         page.enqueue_query(network_query)
 
         page.expose_js_metadata()
@@ -537,6 +535,8 @@ class PlatformsView(TemplateView):
 
         return context
 
+
+
 # View for 1 platform and its details
 class PlatformView(TemplateView):
     template_name = "platform.html"
@@ -594,10 +594,71 @@ class PlatformView(TemplateView):
 
         return context
 
+
+
+#class for my_account
+class AccountView(TemplateView):
+    template_name = "my_account.html"
+    
+    #This view requires login 
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(AccountView, self).dispatch(*args, **kwargs)
+
+
+    def get_context_data(self, **kwargs):
+        page = Page(self.request)
+
+        #network_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform','platform_longname','gateway_type')
+        network_query  = Query().get('local:user').select('user_id','email','config')
+        page.enqueue_query(network_query)
+
+        page.expose_js_metadata()
+        page.expose_queries()
+
+        userlist = SimpleList(
+            title = None,
+            page  = page,
+            key   = 'user_id',
+            query = network_query,
+        )
+
+        context = super(AccountView, self).get_context_data(**kwargs)
+        context['person']   = self.request.user
+        context['users'] = userlist.render(self.request)
+        
+        # XXX This is repeated in all pages
+        # more general variables expected in the template
+        context['title'] = 'Platforms connected to MySlice'
+        # the menu items on the top
+        context['topmenu_items'] = topmenu_items('My Account', self.request)
+        # so we can sho who is logged
+        context['username'] = the_user(self.request)
+
+        context.update(page.prelude_env())
+        return context
+
+
+
+
+
+
+@login_required
+# View for my_account form
+#def my_account(request):
+#    return render(request, 'my_account.html', {
+#        #'form': form,
+#        'topmenu_items': topmenu_items('My Account', request),
+#        'username': the_user (request)
+#    })
+
+
+@login_required
 #my_acc form value processing
 def acc_process(request):
     # getting the user_id from the session [now hardcoded]
     get_user = PendingUser.objects.get(id='1') # here we will get the id/email from session e.g., person.email
+    # getting user info from manifold
     if 'submit_name' in request.POST:
         edited_first_name =  request.POST['fname']
         edited_last_name =  request.POST['lname']
@@ -621,7 +682,7 @@ def acc_process(request):
         get_user.last_name = edited_last_name
         get_user.save() 
 
-        return HttpResponse('Success: Name Updated!!')       
+        return HttpResponse('Sucess: First Name and Last Name Updated!')       
     elif 'submit_pass' in request.POST:
         edited_password = request.POST['password']
         # select the logged in user [for the moment hard coded]
@@ -631,35 +692,41 @@ def acc_process(request):
         get_user.save()
         return HttpResponse('Success: Password Changed!!')
     elif 'generate' in request.POST:
-        #import os
-        #from M2Crypto import Rand, RSA, BIO
-
-        KEY_LENGTH = 2048
-
-        def blank_callback():
-            "Replace the default dashes"
-            return
-
-        # Random seed
-        Rand.rand_seed (os.urandom (KEY_LENGTH))
-        # Generate key pair
-        key = RSA.gen_key (KEY_LENGTH, 65537, blank_callback)
-        # Create memory buffers
-        pri_mem = BIO.MemoryBuffer()
-        pub_mem = BIO.MemoryBuffer()
-        # Save keys to buffers
-        key.save_key_bio(pri_mem, None)
-        key.save_pub_key_bio(pub_mem)
-
-        # Get keys 
-        public_key = pub_mem.getvalue()
-        private_key = pri_mem.getvalue()
+        # 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()
+       
+# DEPRECATED
+#        KEY_LENGTH = 2048
+#
+#        def blank_callback():
+#            "Replace the default dashes"
+#            return
+#
+#        # Random seed
+#        Rand.rand_seed (os.urandom (KEY_LENGTH))
+#        # Generate key pair
+#        key = RSA.gen_key (KEY_LENGTH, 65537, blank_callback)
+#        # Create memory buffers
+#        pri_mem = BIO.MemoryBuffer()
+#        pub_mem = BIO.MemoryBuffer()
+#        # Save keys to buffers
+#        key.save_key_bio(pri_mem, None)
+#        key.save_pub_key_bio(pub_mem)
+#
+#        # Get keys 
+#        public_key = pub_mem.getvalue()
+#        private_key = pri_mem.getvalue()
+        private_key = ''.join(private_key.split())
+        public_key = "ssh-rsa " + public_key
         # Saving to DB
         keypair = '{"user_public_key":"'+ public_key + '", "user_private_key":"'+ private_key + '"}'
-        keypair = re.sub("\r", "", keypair)
-        keypair = re.sub("\n", "\\n", keypair)
-        #keypair = keypair.rstrip('\r\n')
-        keypair = ''.join(keypair.split())
+#        keypair = re.sub("\r", "", keypair)
+#        keypair = re.sub("\n", "\\n", keypair)
+#        #keypair = keypair.rstrip('\r\n')
+#        keypair = ''.join(keypair.split())
         get_user.keypair = keypair
         get_user.save()
         return HttpResponse('Success: New Keypair Generated! %s' % keypair)
@@ -721,35 +788,44 @@ def register_4m_f4f(request):
             #return HttpResponse("Email Already exists")
             #return render(request, 'register_4m_f4f.html')
         if 'generate' in request.POST['question']:
-            #import os
-            #from M2Crypto import Rand, RSA, BIO
-            
-            KEY_LENGTH = 2048
-
-            def blank_callback():
-                "Replace the default dashes"
-                return
-
-            # Random seed
-            Rand.rand_seed (os.urandom (KEY_LENGTH))
-            # Generate key pair
-            key = RSA.gen_key (KEY_LENGTH, 65537, blank_callback)
-            # Create memory buffers
-            pri_mem = BIO.MemoryBuffer()
-            pub_mem = BIO.MemoryBuffer()
-            # Save keys to buffers
-            key.save_key_bio(pri_mem, None)
-            key.save_pub_key_bio(pub_mem)
-            # Get keys 
-            public_key = pub_mem.getvalue()
-            private_key = pri_mem.getvalue()
+            # 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()
+
+# DEPRECATED
+#            #import os
+#            #from M2Crypto import Rand, RSA, BIO
+#            
+#            KEY_LENGTH = 2048
+#
+#            def blank_callback():
+#                "Replace the default dashes"
+#                return
+#
+#            # Random seed
+#            Rand.rand_seed (os.urandom (KEY_LENGTH))
+#            # Generate key pair
+#            key = RSA.gen_key (KEY_LENGTH, 65537, blank_callback)
+#            # Create memory buffers
+#            pri_mem = BIO.MemoryBuffer()
+#            pub_mem = BIO.MemoryBuffer()
+#            # Save keys to buffers
+#            key.save_key_bio(pri_mem, None)
+#            key.save_pub_key_bio(pub_mem)
+#            # Get keys 
+#            public_key = pub_mem.getvalue()
+#            private_key = pri_mem.getvalue()
+
+            private_key = ''.join(private_key.split())
+            public_key = "ssh-rsa " + public_key
             # Saving to DB
             keypair = '{"user_public_key":"'+ public_key + '", "user_private_key":"'+ private_key + '"}'
-            keypair = re.sub("\r", "", keypair)
-            keypair = re.sub("\n", "\\n", keypair)
-            #keypair = keypair.rstrip('\r\n')
-            keypair = ''.join(keypair.split())
-            #return HttpResponse(keypair)
+#            keypair = re.sub("\r", "", keypair)
+#            keypair = re.sub("\n", "\\n", keypair)
+#            #keypair = keypair.rstrip('\r\n')
+#            keypair = ''.join(keypair.split())
         else:
             up_file = request.FILES['user_public_key']
             file_content =  up_file.read()
@@ -844,7 +920,7 @@ def contact(request):
 
     })
 
-
+@login_required
 def slice_request(request):
     errors = []