@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
if thread == None:
abort(404, "Thread not found.")
- thr["unread"] = False
+ thread["unread"] = False
threads_index.sync()
response.content_type = "application/json"
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)
// 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
}
}
});
+*/
}]);
/* Controllers */
-angular.module('KiteMail.controllers', []).
+angular.module('KiteMail.controllers', ['KiteMail.services']).
controller('InboxesListController', function($scope) {
$scope.inboxes = [
{"name": "Inbox", },
{"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) {
};
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);
};
}).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);
});
},