Sfoglia il codice sorgente

fixes #117: /info path to fetch current user and other info

Davide Alberani 8 anni fa
parent
commit
0c664a955d
4 ha cambiato i file con 35 aggiunte e 5 eliminazioni
  1. 1 0
      angular_app/index.html
  2. 6 4
      angular_app/js/controllers.js
  3. 14 0
      angular_app/js/services.js
  4. 14 1
      eventman_server.py

+ 1 - 0
angular_app/index.html

@@ -58,6 +58,7 @@
                 <div class="collapse navbar-collapse">
                     <ul class="nav navbar-nav navbar-right">
                         <li>
+                            <span ng-if="current_user" class="btn">{{current_user}}</span>
                             <button  class="btn btn-link">
                                 <span class="fa fa-sign-out vcenter"></span>
                                 <a href="/logout">{{'logout' | translate}}</a>

+ 6 - 4
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', '$location', 'Setting',
-    function ($scope, $location, Setting) {
+eventManControllers.controller('NavigationCtrl', ['$scope', '$location', 'Setting', 'Info',
+    function ($scope, $location, Setting, Info) {
         $scope.logo = {};
 
         $scope.go = function(url) {
@@ -21,6 +21,10 @@ eventManControllers.controller('NavigationCtrl', ['$scope', '$location', 'Settin
             }
         });
 
+        Info.get({}, function(data) {
+            $scope.current_user = data.current_user || '';
+        });
+
         $scope.isActive = function(view) {
             if (view === $location.path()) {
                 return true;
@@ -85,7 +89,6 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', '
                 }
             });
             modalInstance.result.then(function() {
-                console.debug('here');
                 Event.remove({'id': _id}, function() {
                     $scope.events = Event.all();
                     }
@@ -388,7 +391,6 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting'
                 }
             });
             modalInstance.result.then(function() {
-                console.debug('here');
                 Person.remove({'id': _id}, function() {
                     $scope.persons = Person.all();
                     }

+ 14 - 0
angular_app/js/services.js

@@ -133,6 +133,20 @@ eventManServices.factory('Setting', ['$resource',
 );
 
 
+eventManServices.factory('Info', ['$resource',
+    function($resource) {
+        return $resource('info/', {}, {
+            get: {method: 'GET',
+                isArray: false,
+                transformResponse: function(data, headers) {
+                    return angular.fromJson(data).info || {};
+                }
+            }
+        });
+    }]
+);
+
+
 /* WebSocket collection used to update the list of persons of an Event. */
 eventManApp.factory('EventUpdates', ['$websocket', '$location', '$log',
     function($websocket, $location, $log) {

+ 14 - 1
eventman_server.py

@@ -52,7 +52,7 @@ def authenticated(method):
         # If no authentication was required from the command line or config file.
         if not self.authentication:
             return method(self, *args, **kwargs)
-        # un authenticated API calls gets redirected to /v1.0/[...]
+        # authenticated API calls gets redirected to /v1.0/[...]
         if self.is_api() and not self.current_user:
             self.redirect('/v%s%s' % (API_VERSION, self.get_login_url()))
             return
@@ -573,6 +573,18 @@ class SettingsHandler(BaseHandler):
         self.write({'settings': settings})
 
 
+class InfoHandler(BaseHandler):
+    """Handle requests for Info."""
+    @gen.coroutine
+    @authenticated
+    def get(self, **kwds):
+        info = {}
+        current_user = self.get_current_user()
+        if current_user:
+            info['current_user'] = current_user
+        self.write({'info': info})
+
+
 class WebSocketEventUpdatesHandler(tornado.websocket.WebSocketHandler):
     """Manage websockets."""
     def _clean_url(self, url):
@@ -727,6 +739,7 @@ def run():
             (r"/(?:index.html)?", RootHandler, init_params),
             (r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params),
             (r"/settings", SettingsHandler, init_params),
+            (r"/info", InfoHandler, init_params),
             _ws_handler,
             (r'/login', LoginHandler, init_params),
             (r'/v%s/login' % API_VERSION, LoginHandler, init_params),