several changes on auth flow

Change-Id: I49ddbb074a9bc018b9e5becafbe5956fa5860333
Signed-off-by: lombardofr <lombardo@everyup.it>
diff --git a/vimhandler/template/vim_create.html b/vimhandler/template/vim_create.html
index 4368735..187dc87 100644
--- a/vimhandler/template/vim_create.html
+++ b/vimhandler/template/vim_create.html
@@ -19,7 +19,7 @@
 
 {% block breadcrumb_body %}
     {{ block.super }}
-    <li><a href="{% url 'projects:vims:list' project_id=project_id %}">VIMS</a></li>
+    <li><a href="{% url 'projects:vims:list'  %}">VIMS</a></li>
 {% endblock %}
 
 {% block content_body %}
@@ -27,7 +27,7 @@
 
     <div class="row">
         <div class="col-md-12">
-            <form action='{% url "projects:vims:create" project_id=project_id  %}' method="post">
+            <form action='{% url "projects:vims:create"   %}' method="post">
                 {% csrf_token %}
                 <div class="box">
                     <div class="box-header with-border">
@@ -175,7 +175,7 @@
 
                     </div>
                     <div class="box-footer">
-                        <button onclick="location.href='{% url 'projects:vims:list' project_id=project_id%}'" class="btn btn-default pull-left">Back to
+                        <button onclick="location.href='{% url 'projects:vims:list' %}'" class="btn btn-default pull-left">Back to
                             VIM Accounts
                         </button>
                         <button class="btn btn-primary pull-right">Create</button>
diff --git a/vimhandler/template/vim_list.html b/vimhandler/template/vim_list.html
index 0729e00..535f4db 100644
--- a/vimhandler/template/vim_list.html
+++ b/vimhandler/template/vim_list.html
@@ -19,7 +19,7 @@
 
 {% block breadcrumb_body %}
     {{ block.super }}
-    <li><a href="{% url "projects:vims:list"  project_id=project_id %}">VIMS</a></li>
+    <li><a href="{% url "projects:vims:list"   %}">VIMS</a></li>
 {% endblock %}
 
 {% block content_body %}
@@ -33,7 +33,7 @@
                 <div class="box-header with-border">
                     <h3 class="box-title">Registered VIM</h3>
                     <div class="box-tools">
-                        <a href='{% url "projects:vims:create"  project_id=project_id %}' class="btn btn-block btn-primary btn-sm"><i
+                        <a href='{% url "projects:vims:create"   %}' class="btn btn-block btn-primary btn-sm"><i
                                 class="fa fa-plus"></i><span> New VIM</span></a>
                     </div>
                 </div>
@@ -64,10 +64,10 @@
                                 <td>
                                     <div class="btn-group">
                                         <button type="button" class="btn btn-default"
-                                                onclick="location.href='{% url "projects:vims:show"  project_id=project_id vim_id=p|get:"_id" %}'" data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info"><i
+                                                onclick="location.href='{% url "projects:vims:show"   vim_id=p|get:"_id" %}'" data-toggle="tooltip" data-placement="top" data-container="body" title="Show Info"><i
                                                 class="fa fa-info"></i></button>
                                         <button type="button" class="btn btn-default"
-                                                onclick="javascript:deleteVim('{% url "projects:vims:delete"  project_id=project_id vim_id=p|get:"_id" %}')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete"><i
+                                                onclick="javascript:deleteVim('{% url "projects:vims:delete"   vim_id=p|get:"_id" %}')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete"><i
                                                 class="far fa-trash-alt" ></i></button>
                                     </div>
                                 </td>
diff --git a/vimhandler/template/vim_show.html b/vimhandler/template/vim_show.html
index 74e816a..13613de 100644
--- a/vimhandler/template/vim_show.html
+++ b/vimhandler/template/vim_show.html
@@ -18,7 +18,7 @@
 
 {% block breadcrumb_body %}
     {{ block.super }}
-    <li><a href="{% url 'projects:vims:list' project_id=project_id%}">VIMS</a></li>
+    <li><a href="{% url 'projects:vims:list' %}">VIMS</a></li>
 {% endblock %}
 
 {% block content_body %}
@@ -121,7 +121,7 @@
             </div>
             <div class="box-footer">
                 <div class="">
-                    <button onclick="location.href='{% url 'projects:vims:list' project_id=project_id%}'" class="btn btn-primary">Back to VIM Accounts</button>
+                    <button onclick="location.href='{% url 'projects:vims:list' %}'" class="btn btn-primary">Back to VIM Accounts</button>
                 </div>
             </div>
         </div>
diff --git a/vimhandler/views.py b/vimhandler/views.py
index abaab9c..bf88c11 100644
--- a/vimhandler/views.py
+++ b/vimhandler/views.py
@@ -18,8 +18,8 @@
 from django.contrib.auth.decorators import login_required
 from django.http import HttpResponse
 import json
-#from lib.osm.osmclient.client import Client
 from lib.osm.osmclient.clientv2 import Client
+import authosm.utils as osmutils
 import yaml
 import logging
 
@@ -28,9 +28,11 @@
 
 
 @login_required
-def list(request, project_id):
+def list(request):
+    user = osmutils.get_user(request)
+    project_id = user.project_id
     client = Client()
-    result = client.vim_list(request.session['token'])
+    result = client.vim_list(user.get_token())
     print result
     result = {
         "project_id": project_id,
@@ -40,7 +42,9 @@
 
 
 @login_required
-def create(request, project_id):
+def create(request):
+    user = osmutils.get_user(request)
+    project_id = user.project_id
     result = {'project_id': project_id}
     if request.method == 'GET':
         return __response_handler(request, result, 'vim_create.html')
@@ -70,23 +74,26 @@
             except Exception as e:
                 # TODO return error on json.loads exception
                 print e
-        result = client.vim_create(request.session['token'], vim_data)
+        result = client.vim_create(user.get_token(), vim_data)
         # TODO  'vim:show', to_redirect=True, vim_id=vim_id
-        return __response_handler(request, result, 'projects:vims:list', to_redirect=True, project_id=project_id)
+        return __response_handler(request, result, 'projects:vims:list', to_redirect=True, )
 
 @login_required
-def delete(request, project_id, vim_id=None):
+def delete(request, vim_id=None):
+    user = osmutils.get_user(request)
     try:
         client = Client()
-        del_res = client.vim_delete(request.session['token'], vim_id)
+        del_res = client.vim_delete(user.get_token(), vim_id)
     except Exception as e:
         log.exception(e)
-    return __response_handler(request, {}, 'projects:vims:list', to_redirect=True, project_id=project_id)
+    return __response_handler(request, {}, 'projects:vims:list', to_redirect=True, )
 
 @login_required
-def show(request, project_id, vim_id=None):
+def show(request, vim_id=None):
+    user = osmutils.get_user(request)
+    project_id = user.project_id
     client = Client()
-    result = client.vim_get(request.session['token'], vim_id)
+    result = client.vim_get(user.get_token(), vim_id)
     print result
     if isinstance(result, dict) and 'error' in result and result['error']:
         return render(request, 'error.html')