add a token field to the initialisation of the ammico app so the server can pass it and auto login with jwt
authorrougeronj
Thu, 04 Jun 2015 20:10:38 +0200
changeset 114 e4ffc4e13a8e
parent 113 b8400d8efac8
child 115 8bc06e007fd5
add a token field to the initialisation of the ammico app so the server can pass it and auto login with jwt
client/app/app.js
client/app/books/book.css
client/app/index.html
client/gulpfile.js
--- a/client/app/app.js	Thu Jun 04 20:09:20 2015 +0200
+++ b/client/app/app.js	Thu Jun 04 20:10:38 2015 +0200
@@ -74,11 +74,12 @@
             redirectTo: '/'
         });
     })
-    .run( function($rootScope, $location, $window, $http, authApi) {
+    .run( function($rootScope, $location, $window, $http, authApi, context) {
         $rootScope.globals = {};
-        if (localStorage.getItem('token')) {
+        if (localStorage.getItem('token') || context['token']) {
             $rootScope.globals.userLogged = true;
-            $http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token');
+            localStorage.setItem('token', (localStorage.getItem('token') || context['token']));
+            $http.defaults.headers.common.Authorization = 'Token ' + (localStorage.getItem('token') || context['token']);
         }
         $rootScope.$on( '$routeChangeStart', function(event, next) {
             if (next.authRequired && !$rootScope.globals.userLogged) {
--- a/client/app/books/book.css	Thu Jun 04 20:09:20 2015 +0200
+++ b/client/app/books/book.css	Thu Jun 04 20:10:38 2015 +0200
@@ -30,7 +30,7 @@
 
 .gallery .item.no-img p {
     font-size: 38px;
-    height: 179px;
+    height: 173px;
     padding-top: 25px;
 }
 
--- a/client/app/index.html	Thu Jun 04 20:09:20 2015 +0200
+++ b/client/app/index.html	Thu Jun 04 20:10:38 2015 +0200
@@ -76,7 +76,9 @@
   <script type="text/javascript">
       angular.module("ammico")
           .value('context', {
-              record: angular.fromJson('{"record": "record value"}'),
+              <!-- build:token -->
+  			  <!-- endbuild -->
+			  record: angular.fromJson('{"record": "record value"}'),
               urls: {
                   base_static: "./",
                   ammicoUrl: "http://127.0.0.1:8000/ammico",
--- a/client/gulpfile.js	Thu Jun 04 20:09:20 2015 +0200
+++ b/client/gulpfile.js	Thu Jun 04 20:10:38 2015 +0200
@@ -163,7 +163,8 @@
             imgFooter: {
                 src: 'logo_IRI_footer.png',
                 tpl: '<img src="{% static \'ammico/img/%s\' %}" alt="Logo IRI" />'
-            }
+            },
+            token: '{% if token %} token: "{{ token }}", {% endif %}'
         }))
     .pipe(gulp.dest(templateFolder+'/templates'));
 });