add a token field to the initialisation of the ammico app so the server can pass it and auto login with jwt
--- 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'));
});