]> khamidou — GitHub mirrors - kite.git/commitdiff
multiple user auth
authorkarim hamidou <khamidou@gmail.com>
Wed, 14 May 2014 09:51:00 +0000 (11:51 +0200)
committerkarim hamidou <khamidou@gmail.com>
Wed, 14 May 2014 09:51:00 +0000 (11:51 +0200)
src/back/kite/server.py
src/front/app/js/app.js
src/front/app/js/controllers.js
src/front/app/js/services.js

index 9afeed3d55f3823311f462e499c74d3be7565818..feccdf2698cc443f1806332b653ad00f439c61de 100755 (executable)
@@ -82,7 +82,6 @@ def index(user):
 @get('/kite/<user>/mail/<id>')
 @with_valid_token
 def index(user, id):
-            # FIXME: input sanitization check perms
             try:
                 threads_index = DatetimeCabinet("/home/kite/threads.db")
                 thread = None
@@ -98,7 +97,7 @@ def index(user, id):
             if thread == None:
                 abort(404, "Thread not found.")
 
-            thr["unread"] = False
+            thread["unread"] = False
             threads_index.sync()
 
             response.content_type = "application/json"
@@ -113,6 +112,6 @@ def index(user, id):
             for mail_id in thread["messages"]:
                 ret_json["messages"].append(get_email(mdir, mail_id)) 
 
-            return serialize_json(ret_json)
+            return serialize_json(ret_json, protection=False)
 
 bottle.run(host='localhost', port='8080', reloader=True)
index d4e039116918a496e99213f360ae1013ab8c99f9..2320d08907e1270d2ef2a638e0e40d00e3ccab18 100644 (file)
@@ -3,13 +3,36 @@
 
 // Declare app level module which depends on filters, and services
 angular.module('KiteMail', ['ngRoute', 'ngCookies', 'KiteMail.filters', 'KiteMail.services', 'KiteMail.directives', 'KiteMail.controllers']).
-  config(['$routeProvider', function($routeProvider) {
+  config(['$routeProvider', '$httpProvider', function($routeProvider, $httpProvider) {
     $routeProvider.when('/mail', {templateUrl: 'partials/mailbox.html', controller: 'InboxesListController'});
     $routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'LoginController'});
     $routeProvider.when('/thread/:id', {templateUrl: 'partials/thread.html', controller: 'ThreadController'});
     $routeProvider.otherwise({redirectTo: '/login'});
+
+    var interceptor = ['$rootScope', '$q', '$location', function (scope, $q, $location) {
+        function success(response) {
+            var status = response.status;
+            // user is unauthorized.
+            if (status == 401) {
+                //window.location = "/account/login?redirectUrl=" + Base64.encode(document.URL);
+                $location.path("/login");
+                return;
+            }
+
+            return response;
+        }
+        function error(response) {
+                        // otherwise
+            return $q.reject(response);
+        }
+        return function (promise) {
+            return promise.then(success, error);
+        }
+    }];
+    $httpProvider.responseInterceptors.push(interceptor);
+
   }]).run(['$rootScope', '$location', 'Auth', function($rootScope, $location, Auth) { 
-   $rootScope.$on( "$routeChangeStart", function(event, next, current) {
+/*   $rootScope.$on( "$routeChangeStart", function(event, next, current) {
         console.log(Auth.loggedIn());
         if (!Auth.loggedIn()) {
             // no logged user, redirect to /login
@@ -22,4 +45,5 @@ angular.module('KiteMail', ['ngRoute', 'ngCookies', 'KiteMail.filters', 'KiteMai
             }
         }
     }); 
+*/
   }]);
index 5526b05005e9c935972ef78f08854ffbcfb19dc7..e19c5d1a7e9c885959192331995502edf613f3d5 100644 (file)
@@ -2,7 +2,7 @@
 
 /* Controllers */
 
-angular.module('KiteMail.controllers', []).
+angular.module('KiteMail.controllers', ['KiteMail.services']).
   controller('InboxesListController', function($scope) {
         $scope.inboxes = [
             {"name": "Inbox", },
@@ -10,7 +10,8 @@ angular.module('KiteMail.controllers', []).
             {"name": "Spam",  },];
             
 }).controller('MailsListController', ['$scope', 'Emails', 'Auth', function($scope, Emails, Auth) {
-        $scope.threads = Emails.threads({username: "testuser"});
+        console.log(Auth.username());
+        $scope.threads = Emails.threads({username: Auth.username()});
 }]).controller('LoginController', ['$scope', '$location', 'Auth', function($scope, $location, Auth) {
     $scope.doLogin = function(isValid) {
         if(isValid) {
@@ -23,11 +24,10 @@ angular.module('KiteMail.controllers', []).
             };
 
             Auth.doLogin($scope.username, $scope.password, success, failure); 
-            console.log("PASS" + $scope.password);            
         }
     }    
-}]).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', function($scope, $routeParams, $sce, Emails) {
-    $scope.thread = Emails.thread({username: "testuser", "id": $routeParams.id});
+}]).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', 'Auth', function($scope, $routeParams, $sce, Emails, Auth) {
+    $scope.thread = Emails.thread({username: Auth.username(), "id": $routeParams.id});
     $scope.trustHTML = function(html_code) {
         return $sce.trustAsHtml(html_code);
     };
index 5934cc078820db8e2fd03ebebbdec07fa647dd2a..48c2d14be1d37723c1eccb74b0f44f8279a921be 100644 (file)
@@ -43,17 +43,17 @@ factory('Emails', ['$resource',
 }).factory('Auth', ['$cookies', '$http', 
     function($cookies, $http) {
         var _isAuth = false;
-        var _username = null
+        var _username = null;
         var _cookies = $cookies;
         return {
             loggedIn: function() { return _isAuth; },
-            username: _username,
+            username: function() { return _username; },
+            doLogout: function() { _isAuth = false; },
             doLogin: function(username, password, success, failure) {
-                _username = username;
                 $http({url: '/kite/auth', method:'POST',  data: {"username": username, "password": password}}).
                             success(function(data, status, headers, config) {
+                                _username = username;
                                 _isAuth = true;
-                                $http.defaults.headers.common["X-XSRF-TOKEN"] = "BLAH";
                                 success(data);
                             });
             },