This is an automated email from the git hooks/post-receive script. unknown user pushed a commit to branch devel in repository Pollen. commit c49a891ec0bb111d0a023b12eb0592c46b926d2b Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Tue May 20 16:59:15 2014 +0200 Fix Header Accept-Language value, Add Session Token in header --- pollen-ui-angular/src/main/webapp/js/app.js | 18 ++++++++++++- .../src/main/webapp/js/controllers/userCtrl.js | 15 +++++++---- pollen-ui-angular/src/main/webapp/js/services.js | 31 +++++++--------------- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/pollen-ui-angular/src/main/webapp/js/app.js b/pollen-ui-angular/src/main/webapp/js/app.js index d7e72ee..abd0c0a 100644 --- a/pollen-ui-angular/src/main/webapp/js/app.js +++ b/pollen-ui-angular/src/main/webapp/js/app.js @@ -20,14 +20,30 @@ */ angular.module('pollen', ['pollenServices', 'ngRoute', 'pollControllers', 'userControllers', 'ui.bootstrap', 'ngCookies']) .config(['$httpProvider', '$cookiesProvider', function($httpProvider, $cookies) { + // edit header for locale and sessionToken + $httpProvider.interceptors.push('httpRequestInterceptor'); + + // edit content-type for send data to the server $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; //$httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; +}]) +.factory('httpRequestInterceptor', ['$cookies', function ($cookies) { + // set locale with browser preference + // default : en if (!angular.isDefined($cookies.locale)) { var locale = navigator.language || navigator.userLanguage || 'en'; $cookies.locale = locale.substring(0,2); } - $httpProvider.defaults.headers.common['Accept-Language'] = $cookies.locale; + + + return { + request: function($config) { + $config.headers['Accept-Language'] = $cookies.locale; + $config.headers['X-Pollen-Session-Token'] = $cookies.sessionToken; + return $config; + } + }; }]) .config(['$routeProvider', function($routeProvider) { diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js index a484de4..b99340b 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js @@ -29,18 +29,23 @@ $scope.submit = function () { if ($scope.data.user.password == $scope.data.user.password2) { User.add({}, $scope.data.user, function (data) { - }, function (error) { - $scope.restError = error.data; - }); + }, function (error) { + $scope.restError = error.data; + }); } } }]) -.controller('UserLoginCtrl', ['$scope', 'UserLogin', function ($scope, UserLogin) { +.controller('UserLoginCtrl', ['$scope', 'UserLogin', 'User','$cookies', function ($scope, UserLogin, User,$cookies) { if (!angular.isDefined($scope.data)) { $scope.data = {user:{}}; } $scope.login = function () { - UserLogin.login({}, $scope.data.user); + UserLogin.login({}, $scope.data.user, function (data) { + User.get({userId: data.id}, function (user) { + $scope.currentUser = user; + }) + $cookies.sessionToken = data.permission; + }); } }]) \ No newline at end of file diff --git a/pollen-ui-angular/src/main/webapp/js/services.js b/pollen-ui-angular/src/main/webapp/js/services.js index eb4c5c4..7c163ea 100644 --- a/pollen-ui-angular/src/main/webapp/js/services.js +++ b/pollen-ui-angular/src/main/webapp/js/services.js @@ -20,18 +20,7 @@ */ angular.module('pollenServices', ['ngResource']) -.factory('RestInfo', ['$cookies', function ($cookies) { - var query = ''; - - if (angular.isDefined($cookies.token)) { - query += '&permission='+$cookies.token; - } - - return query; - -}]) - -.factory('Poll', ['$resource', 'RestInfo', function ($resource, RestInfo) { +.factory('Poll', ['$resource', function ($resource) { return $resource(conf.restURL+'/polls/:pollId/:cmd', {pollId:'@id'}, { 'add' : { method : 'POST', @@ -45,15 +34,15 @@ angular.module('pollenServices', ['ngResource']) 'update' : { method : 'POST', transformRequest : function (data, headersGetter) { - return 'poll='+encodeURIComponent(JSON.stringify(data))+RestInfo; + return 'poll='+encodeURIComponent(JSON.stringify(data)); } } }); }]) -.factory('PollChoice', ['$resource', 'RestInfo', function ($resource, RestInfo) { +.factory('PollChoice', ['$resource', function ($resource) { var transformParam = function (data) { - return 'choice='+encodeURIComponent(JSON.stringify(data))+RestInfo; + return 'choice='+encodeURIComponent(JSON.stringify(data)); }; return $resource(conf.restURL+'/polls/:pollId/choices/:choiceId', {choiceId : '@id'}, @@ -75,9 +64,9 @@ angular.module('pollenServices', ['ngResource']) ); }]) -.factory('PollVote', ['$resource', 'RestInfo', function ($resource, RestInfo) { +.factory('PollVote', ['$resource', function ($resource) { var transformParam = function (data) { - return 'vote='+encodeURIComponent(JSON.stringify(data))+RestInfo; + return 'vote='+encodeURIComponent(JSON.stringify(data)); }; return $resource(conf.restURL+'/polls/:pollId/votes/:voteId', {voteId : '@id'}, @@ -99,9 +88,9 @@ angular.module('pollenServices', ['ngResource']) ); }]) -.factory('User', ['$resource', 'RestInfo', function ($resource, RestInfo) { +.factory('User', ['$resource', function ($resource) { var transformParam = function (data) { - return 'user='+encodeURIComponent(JSON.stringify(data))+'&generatePassword=false'+RestInfo; + return 'user='+encodeURIComponent(JSON.stringify(data))+'&generatePassword=false'; } return $resource(conf.restURL+'/users/:userId', {userId : '@id'}, { @@ -122,7 +111,7 @@ angular.module('pollenServices', ['ngResource']) ); }]) -.factory('UserLogin', ['$resource', 'RestInfo', function ($resource, RestInfo) { +.factory('UserLogin', ['$resource', function ($resource) { var transformParam = function (data) { var query = 'login='+encodeURIComponent(data.login); query += '&password='+encodeURIComponent(data.password); @@ -132,7 +121,7 @@ angular.module('pollenServices', ['ngResource']) } else { query += "false"; } - return query+RestInfo; + return query; } return $resource(conf.restURL+'/login', {}, { -- To stop receiving notification emails like this one, please contact Chorem.org SCM administrator <admin+scm@chorem.org>.