From: karim hamidou Date: Tue, 6 May 2014 14:38:57 +0000 (+0200) Subject: initial work on implementing login X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cdca427b832e52d88302322c7788322a6a30d439;p=kite.git initial work on implementing login --- diff --git a/src/back/kite/server.py b/src/back/kite/server.py index f87b0e2..8a037f5 100755 --- a/src/back/kite/server.py +++ b/src/back/kite/server.py @@ -2,11 +2,26 @@ import bottle import json import sys +import users from cabinet import DatetimeCabinet -from bottle import route, template, response, abort +from bottle import route, template, response, abort, get, post from maildir import * from utils import serialize_json +@post('/kite/auth') +def index(): + username = request.forms.get('username', None) + password = request.forms.get('password', None) + if username == None or password == None: + response.status = 401 + return + + if users.auth_user(username, password): + response.status = 200 + token = users.gen_token(username, password) + response.set_cookie('XSRF-TOKEN', token, max_age=86400, httponly=False) + return + @route('/kite//mail') def index(user): # FIXME: input sanitization - check permissions for user diff --git a/src/back/kite/users.py b/src/back/kite/users.py index ba15c4e..5d9be5a 100644 --- a/src/back/kite/users.py +++ b/src/back/kite/users.py @@ -5,34 +5,14 @@ import jsonfile class UserError(Exception): pass - -def create_user(name, _base_folder=os.path.expanduser("~")): - """Create the basic structure for an user. Note: _base_folder is only used for testing""" - try: - os.mkdir(os.path.join(_base_folder, name)) - except OSError: - raise UserError("Folder %s already exists" % name) - -def get_threads_index_folder(email_path): - """This function gets the directory where the threads_index file of an user is located. - It's called by the inotify daemon with the full path of a new email. - ex: get_threads_index_folder("/home/kite/Maildirs/testuser/new/1234563.mail") => "/home/kite/Maildirs/testuser" - """ - return os.path.abspath(os.path.join(os.path.dirname(email_path), os.path.pardir)) - def get_username_from_folder(email_path): """This function get the username from a maildir. ex: get_username_from_folder("/home/kite/Maildirs/testuser/new/1234563.mail") => "testuser" """ - fullpath = get_threads_index_folder(email_path) - return os.path.basename(os.path.normpath(fullpath)) - -def get_user_threads_index(email_path): - folder_name = get_threads_index_folder(email_path) - fullpath = os.path.join(folder_name, "threads_index.json") - - jfile = jsonfile.JsonFile(fullpath) + # FIXME: refactor this monstrosity + return os.path.basename(os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(email_path), os.path.pardir)))) - if not os.path.exists(fullpath): # the threads_index file doesn't exists yet - jfile.data = [] +def auth_user(username, password): + return True - return jfile +def gen_token(username, password): + return "BLAHBLAH" diff --git a/src/back/kite/utils.py b/src/back/kite/utils.py index 513be2e..79cb202 100644 --- a/src/back/kite/utils.py +++ b/src/back/kite/utils.py @@ -15,7 +15,9 @@ class DatetimeEncoder(json.JSONEncoder): return json.JSONEncoder.default(self, obj) def serialize_json(obj): - return json.dumps(obj, cls=DatetimeEncoder) + # we prepend this strange string to prevent jsonp vulnerabilities. + # see: https://docs.angularjs.org/api/ng/service/$http for more info. + return ")]}',\n" + json.dumps(obj, cls=DatetimeEncoder) def deserialize_json(string): return json.loads(string, object_hook=deserialize_datetime) diff --git a/src/front/app/css/bootstrap-theme.css b/src/front/app/css/bootstrap-theme.css index 6935753..60dd1bf 100644 --- a/src/front/app/css/bootstrap-theme.css +++ b/src/front/app/css/bootstrap-theme.css @@ -76,6 +76,7 @@ body { border: 1px solid #aaa; border-radius: 3px; padding: 10px; + margin-bottom: 0px; } /* topbar */ @@ -162,17 +163,19 @@ ul.inboxList li.currentInbox { border-top: 1px solid #ccc; } -button.btn { +input[type="input"].btn, button.btn { border-radius: 3px; } -button.btn.btn-primary { +input[type="input"].btn.btn-primary, button.btn.btn-primary { background-image: linear-gradient(to bottom, #889ED3, #4162AF); background-image: -webkit-linear-gradient(top, #889ED3, #4162AF); background-image: -o-linear-gradient(top, #889ED3, #4162AF); background-image: -ms-linear-gradient(top, #889ED3, #4162AF); } +input[type="input"].btn.btn-primary:hover, +input[type="input"].btn.btn-primary:focus, button.btn.btn-primary:hover, button.btn.btn-primary:focus { background-position: 0px; diff --git a/src/front/app/js/controllers.js b/src/front/app/js/controllers.js index a42f260..244bbe6 100644 --- a/src/front/app/js/controllers.js +++ b/src/front/app/js/controllers.js @@ -9,15 +9,17 @@ angular.module('KiteMail.controllers', []). {"name": "Trash", }, {"name": "Spam", },]; -}).controller('MailsListController', ['$scope', 'Emails', function($scope, Emails) { +}).controller('MailsListController', ['$scope', 'Emails', 'Auth', function($scope, Emails, Auth) { $scope.threads = Emails.threads({username: "testuser"}); -}]).controller('LoginController', function($scope) { - -}).controller('ThreadController', ['$scope', '$routeParams', '$sce', 'Emails', function($scope, $routeParams, $sce, Emails) { +}]).controller('LoginController', ['Auth', function($scope, Auth) { + $scope.doLogin = function() { + if($scope.password) { + 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}); - console.log("YOLO"); $scope.trustHTML = function(html_code) { - console.log("called"); return $sce.trustAsHtml(html_code); }; }]); diff --git a/src/front/app/js/services.js b/src/front/app/js/services.js index 72e3080..9c6a73b 100644 --- a/src/front/app/js/services.js +++ b/src/front/app/js/services.js @@ -41,6 +41,22 @@ factory('Emails', ['$resource', return (date+'').split(' '); } }; -}); +}).factory('Auth', ['$http', function() { + var _isAuth = false; + var _username = null + return { + isAuth: _isAuth, + username: _username, + doLogin: function(username, password, success, failure) { + _username = username; + $http.post({url: '/kite/auth', params: {"username": username, "password": password}}). + success(function(data, status, headers, config) { + sucess(data); + }); + }, + + }; + +}]); diff --git a/src/front/app/partials/login.html b/src/front/app/partials/login.html index 79d3669..983dab3 100644 --- a/src/front/app/partials/login.html +++ b/src/front/app/partials/login.html @@ -1,26 +1,25 @@
-
+
- +
- +
-
- +