diff --git a/src/main/webapp/assets/modules/common/cleanup.fac.js b/src/main/webapp/assets/modules/common/cleanup.fac.js index 653ae1b4e..fcdb384b1 100644 --- a/src/main/webapp/assets/modules/common/cleanup.fac.js +++ b/src/main/webapp/assets/modules/common/cleanup.fac.js @@ -12,6 +12,12 @@ angular.module("Common").factory("cleanupFactory", function (jsonValue, utils, l cleanSession: function () { $rootScope.userInfo = undefined; localStorageService.cookie.remove(jsonValue.storage.key); + }, + + cleanBack2Me: function() { + if (utils.getView() !== jsonValue.views.signIn) { + localStorageService.remove(jsonValue.storage.back2Me); + } } } @@ -23,5 +29,6 @@ angular.module("Common").factory("cleanupFactory", function (jsonValue, utils, l utils.registerNotification(jsonValue.notifications.cleanSession, $$.cleanSession); utils.registerNotification(jsonValue.notifications.loginFailed, $$.cleanSession); utils.registerNotification(jsonValue.notifications.logoutSuccess, $$.cleanSession); + utils.registerNotification(jsonValue.notifications.changeUrl, $$.cleanBack2Me); return instance; }); \ No newline at end of file diff --git a/src/main/webapp/assets/modules/common/connection.fac.js b/src/main/webapp/assets/modules/common/connection.fac.js index 4e82f25a6..edbb1933c 100644 --- a/src/main/webapp/assets/modules/common/connection.fac.js +++ b/src/main/webapp/assets/modules/common/connection.fac.js @@ -61,7 +61,6 @@ angular.module("Common").factory("connectionFactory", localStorageService.set(jsonValue.storage.back2Me, "true"); return utils.sendNotification(jsonValue.notifications.loginFailed); } - return utils.sendNotification(jsonValue.notifications.http404); } } @@ -101,7 +100,6 @@ angular.module("Common").factory("connectionFactory", utils.sendNotification(jsonValue.notifications.userInfo, userInfo); }) .catch(function() { - //localStorageService.set(jsonValue.storage.back2Me, "true"); utils.sendNotification(jsonValue.notifications.notUserInfo); }); diff --git a/src/main/webapp/assets/modules/common/history.fac.js b/src/main/webapp/assets/modules/common/history.fac.js index 9eb08c5e8..be3954400 100644 --- a/src/main/webapp/assets/modules/common/history.fac.js +++ b/src/main/webapp/assets/modules/common/history.fac.js @@ -1,6 +1,6 @@ angular.module("Common").factory("historyFactory", function (jsonValue, $location, $rootScope, utils) { var historyStack = []; - //var exceptViews = [jsonValue.views.analyticsSkill, jsonValue.views.signIn]; + var exceptViews = [jsonValue.views.analyticsSkill, jsonValue.views.signIn]; $rootScope.$on('$routeChangeSuccess', function (event, next, current) { switch (utils.getView()) { @@ -8,9 +8,8 @@ angular.module("Common").factory("historyFactory", function (jsonValue, $locatio case jsonValue.views.pieChart: // TODO: #1 - change the body background to black $("body").css("background-color", "#201d1e"); - instance.trackHistory(); } - console.log(historyStack); + instance.trackHistory(); utils.sendNotification(jsonValue.notifications.changeUrl/*, current.$$route.originalPath, next.$$route.originalPath*/); }); @@ -25,8 +24,9 @@ angular.module("Common").factory("historyFactory", function (jsonValue, $locatio }, popHistory: function () { - //var url; // remove current item - //do {url = historyStack.pop()} while(exceptViews.indexOf(url) >= 0); + var url; // remove current item + do {url = historyStack.pop()} while(exceptViews.indexOf(url) >= 0); + console.log(historyStack); //if (historyStack.length === 0) return "/"; //return historyStack.pop(); switch (utils.getView()) { diff --git a/src/main/webapp/assets/modules/common/router.ser.js b/src/main/webapp/assets/modules/common/router.ser.js index fa7f4475f..fd73d3af9 100644 --- a/src/main/webapp/assets/modules/common/router.ser.js +++ b/src/main/webapp/assets/modules/common/router.ser.js @@ -7,7 +7,6 @@ angular.module("Common").factory("routerService", function (jsonValue, utils, $l loginSuccess: function () { if (localStorageService.get(jsonValue.storage.back2Me) === "true") { - localStorageService.remove(jsonValue.storage.back2Me); var path = historyFactory.popHistory(); $location.path(path); } @@ -17,17 +16,11 @@ angular.module("Common").factory("routerService", function (jsonValue, utils, $l }, serverError: function () { - //$location.path("/"); + console.log("Unable to connect to server"); }, logoutSuccess: function() { $location.path("/"); - }, - - changeUrl: function() { - if (utils.getView() !== jsonValue.views.signIn) { - localStorageService.remove(jsonValue.storage.back2Me); - } } } @@ -35,7 +28,6 @@ angular.module("Common").factory("routerService", function (jsonValue, utils, $l utils.registerNotification(jsonValue.notifications.logoutSuccess, $$.logoutSuccess); utils.registerNotification(jsonValue.notifications.loginSuccess, $$.loginSuccess); utils.registerNotification(jsonValue.notifications.serverError, $$.serverError); - utils.registerNotification(jsonValue.notifications.changeUrl, $$.changeUrl); var instance = { initialize: function () {} diff --git a/src/main/webapp/assets/modules/common/user.ser.js b/src/main/webapp/assets/modules/common/user.ser.js index 223ae54cd..e0769d302 100644 --- a/src/main/webapp/assets/modules/common/user.ser.js +++ b/src/main/webapp/assets/modules/common/user.ser.js @@ -1,9 +1,25 @@ -angular.module("Common").factory("userService", function (jsonValue, utils, connectionFactory, $rootScope, $q) { +angular.module("Common").factory("userService", function (jsonValue, utils, connectionFactory, $rootScope, $q, localStorageService, $cookies) { var defers = { getUserInfo: [] } + var $$ = { + notUserInfo: function() { + $$.reject("getUserInfo"); + }, + + reject: function (key, reply) { + $.each(defers[key], function (i, d) {d.reject(reply);}); + defers[key].length = 0; + }, + + resolve: function (key, reply) { + $.each(defers[key], function (i, d) {d.resolve(reply);}); + defers[key].length = 0; + } + } + var instance = { initialize: function () {}, @@ -11,27 +27,35 @@ angular.module("Common").factory("userService", function (jsonValue, utils, conn var deferred = $q.defer(); defers.getUserInfo.push(deferred); - if (instance.notLoggedIn()) { + if (!instance.verifyUserSession()) { + $$.notUserInfo(); + } + else if (instance.notLoggedIn()) { connectionFactory.findUserInfoByKey(); } else { - instance.resolve("getUserInfo", $rootScope.userInfo); + $$.resolve("getUserInfo", $rootScope.userInfo); } return deferred.promise; }, - resolve: function (key, reply) { - $.each(defers[key], function (i, d) {d.resolve(reply);}); - defers[key].length = 0; - }, - - //TODO: check actual user logged-in notLoggedIn: function () { return ($rootScope.userInfo === undefined); + }, + + verifyUserSession: function() { + return localStorageService.cookie.get(jsonValue.storage.key) !== null; } } - instance.getUserInfo(); //handle refresh button: read user-info + if (instance.verifyUserSession()) { + instance.getUserInfo(); //handle refresh button: read user-info + } + else { + utils.sendNotification(jsonValue.notifications.cleanSession); + } + + utils.registerNotification(jsonValue.notifications.notUserInfo, $$.notUserInfo); utils.registerNotification(jsonValue.notifications.userInfo, instance.getUserInfo); return instance; }); \ No newline at end of file diff --git a/src/main/webapp/assets/modules/register/register.con.js b/src/main/webapp/assets/modules/register/register.con.js index ba9ad8ad7..984167fcb 100644 --- a/src/main/webapp/assets/modules/register/register.con.js +++ b/src/main/webapp/assets/modules/register/register.con.js @@ -5,9 +5,15 @@ angular.module('Register').controller('registerController', $scope.openOathDialog = registerService.openOathDialog; $scope.salaryOptions = registerService.getSalaryOptions(); - userService.getUserInfo().then(function () { - utils.sendNotification(jsonValue.notifications.gotData); - }); + userService.getUserInfo() + .then(function () { + localStorageService.remove(jsonValue.storage.back2Me, "true"); + utils.sendNotification(jsonValue.notifications.gotData); + }) + .catch(function () { + localStorageService.set(jsonValue.storage.back2Me, "true"); + utils.sendNotification(jsonValue.notifications.loginFailed); + }); navigationService.addSpaceforNavi(); navigationService.reSetingPositionLangIcon(); navigationService.keepNaviBar(); diff --git a/src/main/webapp/assets/modules/register/register.ser.js b/src/main/webapp/assets/modules/register/register.ser.js index cc81d2757..8c4c01278 100644 --- a/src/main/webapp/assets/modules/register/register.ser.js +++ b/src/main/webapp/assets/modules/register/register.ser.js @@ -7,6 +7,7 @@ angular.module('Register').factory('registerService', var $$ = { initialize: function ($scope) { scope = $scope; + $('input[type="checkbox"]').checkbox(); $("#salary").slider({}); $('.btn-close').click(function () { @@ -46,10 +47,6 @@ angular.module('Register').factory('registerService', enableNotifications: function () { return utils.getView() === jsonValue.views.register; - }, - - notUserInfo: function() { - localStorageService.set(jsonValue.storage.back2Me, "true"); } } @@ -81,7 +78,7 @@ angular.module('Register').factory('registerService', } }; - utils.registerNotification(jsonValue.notifications.notUserInfo, $$.notUserInfo, $$.enableNotifications); + //utils.registerNotification(jsonValue.notifications.notUserInfo, $$.notUserInfo, $$.enableNotifications); utils.registerNotification(jsonValue.notifications.switchScope, $$.initialize, $$.enableNotifications); return instance; }); \ No newline at end of file diff --git a/src/main/webapp/assets/modules/signin/signin.ser.js b/src/main/webapp/assets/modules/signin/signin.ser.js index 26e508fc3..35c8afd45 100644 --- a/src/main/webapp/assets/modules/signin/signin.ser.js +++ b/src/main/webapp/assets/modules/signin/signin.ser.js @@ -1,6 +1,6 @@ angular.module('SignIn').factory('signInService', function (jsonValue, utils, shortcutFactory, $location, tourService, $auth, localStorageService, - $window, $http, connectionFactory, $rootScope) { + $window, $http, connectionFactory, $rootScope, userService) { var $$ = { enableNotifications: function () { @@ -20,14 +20,14 @@ angular.module('SignIn').factory('signInService', utils.sendNotification(jsonValue.notifications.loading, $(window).height()); // check if user already login - connectionFactory.verifyUserLogin() - .then(function() { - utils.sendNotification(jsonValue.notifications.loginSuccess); - }) - .catch(function() { - $rootScope.userInfo = undefined; - utils.sendNotification(jsonValue.notifications.loaded); - }); + if (userService.verifyUserSession()) { + connectionFactory.verifyUserLogin() + .then(function () {utils.sendNotification(jsonValue.notifications.loginSuccess);}) + .catch(function () {utils.sendNotification(jsonValue.notifications.loginFailed);}); + } + else { + utils.sendNotification(jsonValue.notifications.hideLoadingBox); + } $('.signin-accounts').parallax();