From bb3fb40995ba68d614aa1e8f421465c0076d916b Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 9 Jul 2016 17:18:07 +0200 Subject: [PATCH] fix login redirect --- angular_app/js/app.js | 5 ++++- angular_app/js/controllers.js | 4 ++-- eventman_server.py | 10 +++------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/angular_app/js/app.js b/angular_app/js/app.js index b174973..16600bf 100644 --- a/angular_app/js/app.js +++ b/angular_app/js/app.js @@ -33,6 +33,7 @@ var eventManApp = angular.module('eventManApp', [ eventManApp.run(['$rootScope', '$state', '$stateParams', '$log', 'Info', function($rootScope, $state, $stateParams, $log, Info) { $rootScope.app_uuid = guid(); + $rootScope.info = {}; $log.debug('App UUID: ' + $rootScope.app_uuid); $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; @@ -42,7 +43,9 @@ eventManApp.run(['$rootScope', '$state', '$stateParams', '$log', 'Info', $rootScope.readInfo = function(callback) { Info.get({}, function(data) { $rootScope.info = data || {}; - if (callback) { + if (data.authentication_required && !(data.user && data.user._id)) { + $state.go('login'); + } else if (callback) { callback(data); } }); diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 8c62db8..48f9327 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -7,8 +7,8 @@ var eventManControllers = angular.module('eventManControllers', []); /* A controller that can be used to navigate. */ -eventManControllers.controller('NavigationCtrl', ['$scope', '$rootScope', '$location', 'Setting', 'Info', - function ($scope, $rootScope, $location, Setting, Info) { +eventManControllers.controller('NavigationCtrl', ['$scope', '$rootScope', '$location', 'Setting', 'Info', '$state', + function ($scope, $rootScope, $location, Setting, Info, $state) { $scope.logo = {}; $scope.getLocation = function() { diff --git a/eventman_server.py b/eventman_server.py index a9793a0..5666745 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -244,7 +244,6 @@ class RootHandler(BaseHandler): angular_app_path = os.path.join(os.path.dirname(__file__), "angular_app") @gen.coroutine - @authenticated def get(self, *args, **kwargs): # serve the ./angular_app/index.html file with open(self.angular_app_path + "/index.html", 'r') as fd: @@ -866,12 +865,12 @@ class SettingsHandler(BaseHandler): class InfoHandler(BaseHandler): """Handle requests for information about the logged in user.""" @gen.coroutine - @authenticated def get(self, **kwds): info = {} user_info = self.current_user_info if user_info: info['user'] = user_info + info['authentication_required'] = self.authentication self.write({'info': info}) @@ -904,7 +903,7 @@ class WebSocketEventUpdatesHandler(tornado.websocket.WebSocketHandler): logging.warn('WebSocketEventUpdatesHandler.on_close error closing websocket: %s', str(e)) -class LoginHandler(BaseHandler): +class LoginHandler(RootHandler): """Handle user authentication requests.""" @gen.coroutine @@ -914,9 +913,6 @@ class LoginHandler(BaseHandler): self.set_status(401) self.write({'error': True, 'message': 'authentication required'}) - else: - with open(self.angular_app_path + "/login.html", 'r') as fd: - self.write(fd.read()) @gen.coroutine def post(self, *args, **kwargs): @@ -1024,7 +1020,7 @@ def run(): template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), cookie_secret='__COOKIE_SECRET__', - login_url='/login', + login_url='/#/login', debug=options.debug) ssl_options = {} if os.path.isfile(options.ssl_key) and os.path.isfile(options.ssl_cert):